A quick guide on how to setup Node.js development environment.
Previous versions of these install instructions had been tested with:
- Ubuntu on WSL (Windows Subsystem for Linux)
- Ubuntu 18.04 LTS (Bionic Beaver)
- Ubuntu 17.04 (Zesty Zapus)
- Ubuntu 16.04 LTS (Xenial Xerus)
- Ubuntu 14.04.3 LTS (Trusty)
- macOS 10.14.6 (Mojave)
- macOS 10.13.6 (High Sierra)
- macOS 10.12.6 (Sierra)
- OS X 10.11.6 (El Capitan)
The reason for using nvm instead of other install types is mainly in how easy it is to have multiple versions of Node.js (if needed) without too much of extra complexity. Sometimes applications might require a certain version of Node.js to work, so having the flexibility of using specific versions can save a lot of time from you.
- Open new Terminal window.
- Run nvm installer
- ...with either curl or wget.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
- The script clones the nvm repository to
~/.nvm
and adds the source line to your profile (~/.bash_profile
,~/.zshrc,
~/.profile,
or~/.bashrc
). (You might want/need to add the source loading line by yourself, if the automated install tool does not add it for you.)export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
- ...with either curl or wget.
- If everything went well, you should now be able to reload the shell by running
source ~/.bashrc
- (Another option is to open a new Terminal window/tab.)
- Verify installation
- To verify that nvm has been installed, do:
command -v nvm
- To verify that nvm has been installed, do:
- List what versions of Node are currently installed (probably none).
nvm ls
- Install latest Node.js LTS release (recommended for production usage).
nvm install v10.16.2
- Install Current Node.js Current release with latest features (for testing new feature improvements).
nvm install v12.8.0
- If you want to change the default Node version later, you can run a command to adjust it.
It is also possible to select what Node.js version is used per project basis, by running nvm use v10.16.1
(or another version number) on the directory where the individual project is located. One way to do that is to create small Bash shell script for enabling the right environment when needed, so you would not have to remember what exact version was needed.
You can find a lot of packages from the npm package repository. Have a good time with the freshly installed tools.
If you already have previous version of Node.js installed with nvm, you can migrate packages from previously installed Node.js versions.
- Open new Terminal window (to make sure you have latest Node.js version active in your command line environment).
- Linking global packages from previous version:
nvm reinstall-packages v10.16.1
nvm reinstall-packages v12.7.0
- Look what versions are installed:
nvm ls
- Delete an older version (if it is no longer used in some of your projects):
nvm uninstall v10.16.1
nvm uninstall v12.7.0
npm ls -g --depth=0.
npm outdated -g --depth=0.
npm update -g
After installation of Node v10.x (or similar), it can be a good idea to recompile old packages (that have compiled native extensions) to make sure that they work with the new version of Node. That can be done easily by going to a project’s root directory, and running npm rebuild
:
cd PROJECT_NAME
npm rebuild