Skip to main content

Installing Node.js with nvm to Linux & macOS & WSL

Installing Node.js with nvm to Linux & macOS & WSL


A quick guide on how to setup Node.js development environment.
Previous versions of these install instructions had been tested with:

Install nvm for managing Node.js versions

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.
  1. Open new Terminal window.
  2. 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
  3. 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.)
  4. Verify installation
    • To verify that nvm has been installed, do: command -v nvm
  5. List what versions of Node are currently installed (probably none).
    • nvm ls
  6. Install latest Node.js LTS release (recommended for production usage).
    • nvm install v10.16.0
  7. Install Current Node.js Current release with latest features (for testing new feature improvements).
    • nvm install v12.3.1
  8. If you want to change the default Node version later, you can run a command to adjust it.
    • nvm alias default v10.16.0 (when you work with production quality projects) changelog
    • nvm alias default v12.3.1 (when you want to test the latest features of Node.js) changelog
It is also possible to select what Node.js version is used per project basis, by running nvm use v10.15.3 (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 website. Have a good time with the tools.

Upgrading from previous version of Node.js

If you already have previous version of Node.js installed with nvm, you can upgrade to a different version with these steps.
  • 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.15.3
    • nvm reinstall-packages v12.3.0

Updating outdated packages

List what (top level) packages are installed globally

npm ls -g --depth=0.

List what packages are outdated

npm outdated -g --depth=0.

Update outdated globally installed npm packages

npm update -g

Fixing old package versions

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

Deleting old Node.js versions

  • 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.15.3
    • nvm uninstall v12.3.0

Comments

Post a Comment

Popular posts from this blog

How to setup eth server for PEATIO EXCHANGE

What do you need? An instance with 4G of ram at least 100 G of hard disk Ubuntu 16.04   Install geth sudo apt-get install software-properties-common sudo add-apt-repository -y ppa:ethereum/ethereum sudo apt-get update sudo apt-get install ethereum Run geth copy the geth service file to /etc/systemd/system/geth.service sudo systemctl start geth sudo systemctl enable geth Install Nginx + fcgi sudo apt install nginx -y fcgiwrap copy default file to /etc/nginx/sites-enabled/default sudo systemctl restart nginx cgi files copy the cgi files to /var/www/html/cgi-bin and update total.cgi with your username sudo chown www-data:www-data -R /var/www/html/cgi-bin sudo chmod +x /var/www/html/cgi-bin/* Install filter service copy total.js to /var/www sudo chown www-data:www-data /var/www/total.js don't forget to edit service.rb with your url sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libr...

Tether(USDT) Installation | Command-line Tutorial

What is USDT Tether’s Omni layer constructed by bitcoin block network. On this overlay network, all parties can issue token, tether company. Token, codenamed USDT, was issued on Omni layer, anchoring in US$1:1. Tether’s idea is very simple. You give me the dollar and give me one dollar. I issue 1 USDT. The dollar is deposited in the designated asset account. Everyone can inquire about it. The total amount of USDT issued can also be inquired on the block. When converting, give me 1 USDT and I return 1 dollar. Omni(USDT) Wallet installation 1.Download Omni Layer Wallet    wget https://bintray.com/artifact/download/omni/OmniBinaries/omnicore-0.3.0-x86_64-linux-gnu.tar.gz ux-gn 2.Decompress & Run    tar - xzvf omnicore - 0.3 . 0 - x86_64 - linux - gnu . tar . gz Now, copy Dependent library to Local sudo CP omnicore-0.3.0/lib/*/lib Open the wallet directory cd omnicore-0.3.0/bin ./omnicored Initial star...

Market Research, Financial Insights, Technology Trends, and Consumer Analytics

This list covers market research, financial insights, technology trends, and consumer analytics . 🔹 General Market Research & Industry Reports   1. Market Research Future - https://www.marketresearchfuture.com/   2. Allied Market Research - https://www.alliedmarketresearch.com/   3. Mordor Intelligence - https://www.mordorintelligence.com/   4. Grand Vie w Research - https://www.grandviewresearch.com/   5. Research and Markets - https://www.researchandmarkets.com/   6. IBISWorld - https://www.ibisworld.com/   7. Statista - https://www.statista.com/   8. Fact.MR - https://www.factmr.com/   9. Transparency Market Research -https://www.transparencymarketresearch.com/   10. Global Market Insights - https://www.gminsights.com/   🔹 Technology & Innovation Research    11. Technavio - https://www.technavio.com/   12. Forrester Research - https://www.forrest...