-
Notifications
You must be signed in to change notification settings - Fork 18
Installing NodeJS and NPM
NodeJS is a server-side JavaScript runtime built that is designed to build scalable network applications. When you install NodeJS, also install Node Package Manager (NPM), which is required to set up most of the tools and libraries required for blockchain development.
Throughout the tutorials, you may be required to use different versions of NodeJS and NPM because the tools we are working with are still very unstable and sometimes only work with a specific version of node and npm. Therefore, we suggest using the node version manager, nvm, to install and switch between versions.
It is not required to uninstall your current installation of node and npm, but sometimes the installation process of nvm is smoother if you uninstall your old versions first. To check if NodeJS and NPM are already installed on your machine, use the following command:
$ node -v
$ npm -vIf they are present, you can uninstall them on Ubuntu via
$ sudo apt-get purge nodejs
$ sudo apt-get autoremoveand on macOS via
$ brew uninstall nodeThe installation method uses curl to get the installation package. If you are not sure whether you have curl already installed, run
$ sudo apt-get install curlNext, install nvm running
# download and run the installation script
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
# store the path to nvm
$ export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
# load nvm
$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"Verify that nvm has been properly installed using
$ nvm -vIf you get the response nvm: command not found, close and reopen your terminal. It should be there now.
Since OS X 10.9, /usr/bin/git has been preset by Xcode command line tools, which means the nvm install script can not properly detect if Git is installed or not. You need to manually install the Xcode command line tools before running the nvm install script, otherwise, it will fail.
To check whether Xcode command line tools are already installed, run
$ xcode-select -pIf the response is /Applications/Xcode.app/Contents/Developer, Xcode is already installed but you may want to update Xcode to the newest version. Go to the App Store application and check Updates. After updating Xcode, be sure to launch the Xcode application and accept the Apple license terms.
If Xcode is not already installed, you can install it via
$ xcode-select --installThis will pop up a window that is a bit confusing. You DO NOT need to Get Xcode, simply click Install.
After the installation process is done, verify that you have successfully installed Xcode command line tools by running the following command again:
$ xcode-select -pwhich should respond with /Applications/Xcode.app/Contents/Developer.
To install nvm, you can run the same commands as described in the Ubuntu section.
If you get the response nvm: command not found even after you have closed and reopened the terminal, your system may not have a .bash_profile file where the command is set up. Simply create one with
$ touch ~/.bash_profile and run the install script again:
# download and run the installation script
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
# store the path to nvm
$ export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
# load nvm
$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"To be on the save side, close and reopen the terminal one last time.
Now that nvm is installed, it is very easy to install node and npm. Simply run
$ nvm install nodeto install the latest version. To install a specific version, run
$ nvm install 6.14.4 # or 10.10.0, 8.9.1, etcTo use node and npm, run
# latest version
$ nvm use node
# specific version
$ nvm use 6.14.4 # or 10.10.0, 8.9.1, etcYou may have to close and reopen your terminal to make these changes effective.
You can list all versions that are available via
$ nvm ls-remote