If you are looking to install Node.js on Ubuntu Linux, you are in luck. Node.js is available in Ubuntu repository and you can easily install it in a few commands.
If you are going to install Node.js, I think you already know about Node.js. I’ll recall it quickly anyways.
Node.js “is an open-source, cross-platform runtime environment for developing server-side Web applications”. Its simplicity to build and deploy fast and scalable applications have made it one of the most popular web technology of recent years.
Node.js is supported with npm (Node.js Package Manager). It’s an open source library of Node.js packages. So, you can use them in your application without the need of rewriting the entire thing all by your own.
Enough talking about Node.js and
There are two main ways you can install Node.js and npm on Ubuntu:
- Using Ubuntu’s official repository: Easy to install using apt but might have an older version.
- Using NodeSource repository: Slightly complicated but you can choose which version to install including the latest release of Node.js.
Install Node.js and npm on Ubuntu using official repository
As I said earlier, Node.js is available in Ubuntu. So, all you need to do is to open a terminal and use the following command:
sudo apt install nodejs
To install npm, use the following command:
sudo apt install npm
I recommend installing npm as well because you are going to need it anyways. Both Node.js and npm are not big in size.
For working on Node.js, you can use any good code editor for Linux or IDE. It’s basically your preference.
I am not going to show you how to get started with Node.js because that’s not the purpose of this quick tutorial.
If you want to remove Node.js and npm, you can use the command below:
sudo apt remove nodejs npm
Note: If you are getting “/
What happens here is that the program looks for the
ln -s /usr/bin/nodejs /usr/bin/node
Install Node.js and
npm on Ubuntu using NodeSource repository
You can install Node.js and
What you have to keep in mind that you need to specify which major version of Node.Js you want to install.
Let’s say you want to install Node.Js version 11. You can use the following commands:
curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
If you want to install Node.Js version 10, you can replace setup_11.x with setup_10.x.
The above command will download and start running the installation script. The script will add a new repository in the source list directory (/etc/apt/source.list.d). It will also add the GPG key of the new repository automatically.
With this new repository added to sources list, you can install
To install the Node.js package, use the following command. Npm is also installed with this package.
sudo apt install nodejs
Once installed, you verify it by checking the installed version of Node.js with this command:
The output should be like this:
You may also verify the npm installation:
The output should be similar to this:
That’s all you need to do to install Node.js on Ubuntu 18.04 and 16.04. I hope you find this quick tip helpful. If you have question or suggestions, feel free to leave a comment below.
In the end, if you love Node.js so much, you should check out NodeOS, a Linux distribution for Node.js users.