Node.js has rapidly become an extremely popular part of technology to host dynamic applications on the internet. The cloud has helped such programming languages become a success. Released back in 2009, Node.js is an open-source, cross-platform, back-end JavaScript runtime environment. It’s mainly a server-side scripting language for the front-end language JavaScript, used to produce the dynamic web page content before it’s displayed on the user's web browser. However, it is also very popular as a full-stack and front-end solution.
In this tutorial, we are going to show you how to install Node.js on Ubuntu 18.04. If you are a junior developer and are only starting out with programming and need help with covering the basics of programming, look no further. We are going to cover 3 ways in which you can install Node.js on Ubuntu in this tutorial - using Apt, using a PPA (Personal Package Archive), using nvm. To understand the syntaxes used in this tutorial, you might need some knowledge about the command line tools. With that being said, let’s dive right into the Node.js Ubuntu installation process.
Install Node.js On Ubuntu Using Apt
There exists a version of Node.js in Ubuntu 18.04’s default repositories that can be used to have a consistent coding experience. This means that you don’t need to go for third-party repositories to install a different version for quick experimentation with the language. You can use the apt package manager to obtain the latest version and install Node on Ubuntu. Here’s how:
Step 1: Open Terminal and update the local package manager first. Here’s the syntax:
Step 2: Install Node.js from the repositories:
Step 3: If you are satisfied with the package in the repositories, this is all you need to do to get set up with Node.js. In most cases, however, you will also need to install npm, the Node.js package manager. Type this:
This will allow you to install specific modules and packages for convenience and better usage of Node.js.
Step 4: Finally, to check which version of Node.js you have installed, type in:
You have successfully completed the installation process of Node.js on Ubuntu. If you wish to install different versions of Node.js, we are going to cover more flexible and robust methods of installations, so read on to know more.
Install Node.js On Ubuntu Using a PPA
You can get a more recent Ubuntu Node install by adding the PPA (Personal Package Archive) maintained by NodeSource. This is going to have more up-to-date versions of Node.js than the ones in-built in the Ubuntu repositories and lets you have the versions Node.js v12.x and Node.js v14.x. This can come in extremely handy for senior developers who need upgraded versions of the libraries in Node.js. Here’s how you Ubuntu install Node.js using a PPA:
Step 1: Install the PPA to access its contents. Use the curl tool to retrieve the installation script for your preferred version from the home directory:
Step 2: You can access the contents using the nano text editor or any text editor of your choice:
Step 3: Run the script under sudo:
Step 4: Once the PPA is configured and your local package cache is updated automatically, run the setup script from Nodesource. You can now install the Node.js package the same way you did using apt:
Step 5: To check which version of Node.js Ubuntu installation is on your distro after following these steps, type:
Output
V10.22.0
This node package you just installed contains binary as well as npm packages, so you don’t need to install npm separately as we saw before. Some npm packages require the installation of the build-essential package. Type in the following command to do that:
You have now successfully completed the Node.js Ubuntu install.
Install Node.js On Ubuntu Using Nvm
This method is an alternative to installing Node.js on Ubuntu using a tool called “nvm” which stands for “Node.js Version Manager”. It works with an independent directory within your home directory. One major advantage of using nvm is that you can install multiple self-contained versions of Node.js without affecting the entire system. You can also juggle between the latest and previous versions of Node.js according to your needs. Here’s how you Node.js install Ubuntu using nvm:
Step 1: Download the nvm installation script using curl. Type in the following command on the Terminal:
Step 2: Read the script using nano or any other text editor that you wish to use:
Step 3: Run the script with bash:
Step 4: This will install the software in a subdirectory in your home directory. Once you have nvm installed, you can install multiple versions of Node.js. To access the information of the versions of Node.js available, type in the following command:
The following output will be displayed on your screen, which will show the versions of Node.js available:
Output
...
v12.18.3 (Latest LTS: Erbium)
v13.0.0
v13.0.1
v13.1.0
v13.2.0
v13.3.0
v13.4.0
v13.5.0
v13.6.0
v13.7.0
v13.8.0
v13.9.0
v13.10.0
v13.10.1
v13.11.0
v13.12.0
v13.13.0
v13.14.0
v14.0.0
v14.1.0
v14.2.0
v14.3.0
v14.4.0
v14.5.0
v14.6.0
v14.7.0
Step 5: Here, the current LTS version is 12.18.3. This may vary depending on when you are reading this tutorial. Install the latest LTS version by typing the following command:
Step 6: To see the version you just installed, you need to use an executable called node. This is specific to installations using nvm. Type in the following command to verify the version used by the shell:
Output
v12.18.3
You have now successfully completed the Node.js install in Ubuntu. If you have multiple Node.js versions, you can see what is currently in use by typing:
To default one of the installed versions, type in the following command:
This version will automatically be selected on new sessions.
If you have a query about the options available to you with nvm, by type:
Final Word
You now know how to install Node.js on Ubuntu in 3 different methods. Your circumstances and needs and the level at which you are programming will determine which method is best for you. The first method mentioned is the easiest and least time-consuming and is for beginners. The last method using nvm provides the most flexibility.
If you are a heavy programmer and juggle with storing and accessing data, you should check out the cloud solutions provided by E2E. We, at E2E Cloud, are trusted by 3000 clients across the world, and our customers believe we provide the best solutions at affordable rates. Don’t believe us? Check for yourself!
Know more about E2E Cloud - https://bit.ly/3eaePdo
Contact no - 9599620390 Email - raju.kumar1@e2enetworks.com