How to Install Node.js on Ubuntu
NodeJs is an accessible open source server environment. Many developers have started to use it throughout the past several years. It's an advantageous product and is capable of running on various platforms such as Ubuntu, Linux, Windows, and so on.
There are many ways to install it on Ubuntu, but while doing that, you meet a lot of problems.
So, finally, is there any way which is good, right and not problematic? Yes. Here is a list of commands that you can perform to install NodeJs on your Ubuntu.
- sudo apt-get install python-software-properties python g++ make
- sudo add-apt-repository ppa:chris-lea/node.js
- sudo apt-get update
- sudo apt-get install nodejs
Using NVM to Install Node.js on Ubuntu
NVM stands for Node Version Manager. It is considered a bash script that is applied for managing several active Node.js versions. Any specific version of Node.js can be installed and uninstalled with it.
You need to perform the steps below for installing Node.js and npm with NVM on Ubuntu:
The first step is to install the NVM script via downloading and installing the nvm script run like this
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
This command clones the NVM repository from Github into the ~/.nvm directory.
Here is how the output looks like:
=> Close and reopen your terminal for beginning to use nvm or run the following to use it right away:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # It will load nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # It will load nvm bash_completion
So, you have two options: closing, reopening the terminal or running the commands for adding the path to the nvm script to the current session. You are free to choose the most straightforward option for you.
When the script is already located inside the PATH, it is necessary to verify that the nvm was installed accurately. You should do it as follows:
nvm --version
And, the output is the following:
0.34.0
So, after installing nvm, you will be able to install the latest available Node.js version by acting like this:
nvm install node
You will get this output:
Downloading and installing node v12.8.1...
Downloading https://nodejs.org/dist/v12.8.1/node-v12.8.1-linux-x64.tar.xz... ######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.8.1 (npm v6.10.2)
Creating default alias: default -> node (-> v12.8.1)
After completing the installation, it should be verified through printing the version of Node.js like here:
node --version
Output:
v12.8.1
For installing the latest LTS version, as well as the 8.10.0 version, act as follows:
nvm install --lts
nvm install 8.10.0