Node.js is an open source platform that allows easy scalability of applications. With Node.js installed on Ubuntu, you can run JavaScript without being dependent on any browser. Given its efficiency and speed, it is the absolute choice for data streaming, data-intensive applications that run across distributed applications.
NPM, the world’s largest software registry, goes along with it, being the default package manager for Node.js. The chief use of Node.js is for applications that require building a back end server and also for front end applications.
Below are the steps for installing Node.js on ubuntu.
NOTE: The steps mentioned below are also suitable for any other Ubuntu-based distribution like Linux Mint, Kubuntu and Elementary OS.
Installation of Node.js depends on the need of the user
- For deploying Node.js application
- For development purposes
In case 1, simply access the default Ubuntu repository or NodeSource repository and use apt to install the node.js packages.
In case 2, once you login as a user with sudo privileges, we are good to go!
For this case, we need to install Node.js along with npm package.
Below are 3 ways you can do that.
A. Using the official Ubuntu Repository
As Node.js is available on Ubuntu, simply open a terminal.
sudo apt install nodejs
And then to install npm
sudo apt install npm
B. Using the NodeSource repository
By using the bash script, it requires you to mention the version of Node.js you wish to install
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
This command installs both the Node.js as well as the npm packages
sudo apt install nodejs
To verify the installed Node.js version
node --version
Output:
node --version
v11.6.0
The similar command is used to verify the version of the npm package.
npm --version
C. Using the NVM (Node Version Manager)
You can also install Node.js and nvm by using the NVM. The best part about this method of installing Node.js is that the user can install/uninstall any desired version of Node.js as NVM supports multiple version of Node.js
Download the NVM install script
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
Righ now, we are using github to access the nvm repository. By using this command, we are cloning it and adding the path to our Bash
Output:
# => Close and reopen your terminal to start using nvm or run the following to use it now:
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
Doing either of the mentioned tasks will add the nvm to our path. The user has the choice to select the convenient one.
As the script is now added to our path, we can verify the nvm version
nvm --version
Now nvm is properly installed and hence we can now install Node.js
nvm install node
The output goes like this…
Downloading and installing node v11.0.0…
Downloading https://nodejs.org/dist/v11.0.0/node-v11.0.0-linux-x64.tar.xz…
################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v11.0.0 (npm v6.4.1)
Creating default alias: default -> node (-> v11.0.0)
Verify the Node.js version using
node --version
If you want to uninstall Node.js just use the following command,
sudo apt remove nodejs npm
That’s it folks! The above steps are to be followed and you can easily install node.js on Ubuntu