As a developer, you all know that JavaScript was developed to run on the client-side for websites. We all know that when a user visits a website, all the JavaScript is downloaded from the server to the client’s device and then executed. This not only consumes the bandwidth but also hampers the performance of the website. The best part of using Node.js is that it’s free, open-source, and developers can use it without learning any new programming language.
Node.js is the one that is developed to run JavaScript on the server side. Making the website’s performance faster also gives power to developers to run JavaScript on the server side itself. Being a cross-platform scripting language, developers can execute the script on both server and client as per the need.
In this tutorial, you will learn
How to Install Node.js on Ubuntu
In this tutorial, we are using the DEB repository to install Node.js on the Ubuntu server. Although you can visit the Node.js official website and download according to the Operating System you are using.
Step 1 – Updating the Repository
The first step before installing Node.js is to update the Ubuntu repository.
# sudo apt update
# sudo apt uprade -y
Step 2 – Adding GPG key repository
The next step is to add the GPG key repository
# sudo apt install curl gnupg ca-certificates -y
# sudo curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | # sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
Now, let’s add the Node.js repository
# NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/nodesource.list
# sudo apt update
Step 3 – Install Node.js, Yarn, and npm
The next step is to install Node.js, yarn, and npm. Since we have already added the repository, we just have to execute the commands given below.
# sudo apt install nodejs -y
Let us also install the development tools, which will help us in building native addons
# sudo apt install gcc g++ make -y
Now, let’s install the yarn package manager
# sudo curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor |
# sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
# sudo apt update
# sudo apt install yarn -y
Let’s verify the installations
# node -v
v20.19.5
# npm -v
10.8.2
# yarn -v
1.22.22
Step 4 – Test and Use Node.js
The final step is to create a development environment
# cd ~/
# sudo mkdir nodejs-app
# cd nodejs-app
Let’s initialize a project that will contain the metadata about dependencies and apps to run
# sudo npm install express --save
Output
up to date, audited 69 packages in 704ms
16 packages are looking for funding
run
'npm fund' for details
found 0 vulnerabilities
Conclusion
With this, you have successfully installed Node.js on Ubuntu. Now you can go ahead and start creating your project
Leave a Reply