Friday, October 10, 2025
HomeWeb developmentSet up Node.js on Ubuntu — SitePoint

Set up Node.js on Ubuntu — SitePoint


Node.js has revolutionized the way in which we construct net functions by enabling builders to create scalable community functions utilizing JavaScript on the server facet. To harness the total potential of Node.js, you first want to put in it in your system. On this information, we’ll stroll you thru the method of set up on Ubuntu, a preferred Linux distribution, utilizing three completely different strategies. We’ll additionally cowl stipulations, organising your Node.js surroundings, and uninstalling Node.js if wanted.

Desk of Contents

Key Takeaways

  • Learn to set up Node.js and npm on Ubuntu utilizing the default repository, NodeSource repository or NVM (Node Model Supervisor).
  • Arrange your surroundings by making a challenge listing, initializing a challenge and operating easy packages.
  • Uninstall Node.js from Ubuntu with both apt package deal supervisor or NVM relying on set up methodology used.

Understanding Node.js

Node.js is a server-side JavaScript runtime surroundings that enables builders to construct scalable net functions and APIs utilizing the identical codebase for each server and shopper sides. Its event-driven structure and non-blocking enter/output API make it good for real-time net functions. Putting in Node.js in your net server lets you leverage these options, key to creating state-of-the-art net functions.

Furthermore, Node.js gives quite a few advantages, resembling scalability, fast improvement fee, and a strong group. With an ever-growing variety of packages and modules accessible, Node.js has turn out to be an indispensable device for net builders worldwide.

Conditions for Putting in Node.js on Ubuntu

Make sure you meet the stipulations for putting in Node.js on Ubuntu earlier than initiating the set up course of. Listed below are the stipulations:

  1. You want a appropriate Ubuntu model.
  2. You should have sudo privileges, which you’ll be able to confirm by executing the command sudo whoami and getting into your password when prompted.
  3. A primary understanding of JavaScript and command-line utilization is critical.

There are three distinct strategies for putting in Node.js on Ubuntu:

  1. Utilizing the default Ubuntu repositories
  2. Using the NodeSource repository
  3. Implementing NVM (Node Model Supervisor)

NVM is really helpful for customers who require frequent switching between Node.js variations, because it means that you can handle a number of variations simply.

Methodology 1: Putting in Node.js and npm from Default Ubuntu Repositories

The primary methodology to put in Node.js and npm entails utilizing the default Ubuntu repositories. This strategy is easy and appropriate for many customers. Nonetheless, it could present an older model of Node.js in comparison with different strategies.

The next sections will information you thru the steps to replace the package deal lists, set up Node.js and npm, and confirm the set up.

Replace package deal lists

Make sure that to replace the package deal lists within the terminal previous to putting in Node.js and npm. This ensures that you just get the newest JS variations put in in your system. To replace the package deal lists on Ubuntu, execute the next command within the terminal: sudo apt replace. As soon as the package deal lists are up to date, you possibly can proceed with the set up course of.

Set up Node.js and npm

To put in Node.js and npm utilizing the apt package deal supervisor, execute the command sudo apt set up nodejs within the terminal. Press Y when prompted to verify the set up. This command will set up Node.js from the default Ubuntu repositories, making the method easy and safe.

Subsequent, it is advisable set up npm, the package deal supervisor for Node.js, which lets you simply handle and share your code. To put in npm, first set up node by executing the command sudo apt set up npm.

With Node.js and npm put in, now you can begin operating your JavaScript code and creating net functions.

Confirm set up

As soon as Node.js and npm are put in, it’s essential to verify the success of the set up. To examine if Node.js and npm are put in on the system, execute the instructions node -v and npm -v within the terminal. If the model numbers of each Node.js and npm are displayed, they’ve been put in appropriately, and you can begin operating your JavaScript code.

Methodology 2: Putting in Node.js and npm from NodeSource Repository

The second methodology entails putting in Node.js and npm from the NodeSource repository. This methodology is appropriate for customers who need entry to the newest model of Node.js and npm or want particular releases.

The NodeSource repository is a Private Package deal Archive (PPA) that gives extra variations of Node.js than the default Ubuntu repository. The next sections will information you thru the steps so as to add the NodeSource repository, set up Node.js and npm, and ensure the set up.

Add the NodeSource repository

So as to add the NodeSource repository to your system, you should use curl or wget. First, open a terminal by urgent Ctrl + Alt + T. Then, execute the suitable command to your Ubuntu model, which will be discovered on the NodeSource repository’s GitHub web page. This can obtain and run the set up script, incorporating the NodeSource repository into your system.

As soon as the repository is added, you possibly can proceed with the set up of Node.js and npm.

Set up Node.js and npm

With the NodeSource repository added to your system, now you can set up Node.js and npm. To do that, execute the command sudo apt set up nodejs within the terminal. Press Y when prompted to verify the set up. This command will set up Node.js and npm from the NodeSource repository, offering you with the newest model or a selected launch, relying in your wants.

Affirm set up

Upon putting in Node.js and npm from the NodeSource repository, you’ll want to validate the set up. To do that, execute the instructions node -v and npm -v within the terminal. If the model numbers of each Node.js and npm are displayed, they’ve been put in efficiently, and you can begin operating your JavaScript code.

Methodology 3: Putting in Node.js and npm utilizing NVM (Node Model Supervisor)

NVM is a flexible device for Node.js model administration, permitting you to put in and handle a number of Node.js variations simply. This methodology is right for customers who want to modify between Node.js variations usually or wish to take a look at their functions with completely different variations. We’ve got a full information to utilizing NVM right here.

The next sections will information you thru the steps to put in NVM, choose and set up a Node.js model, and change between put in variations.

Set up NVM

To put in NVM, it is advisable observe these steps:

  1. Open a terminal by urgent Ctrl + Alt + T.
  2. Obtain the NVM set up script utilizing both curl or wget. You’ll find the suitable command within the NVM repository’s README file on GitHub.
  3. Run the NVM set up script. This can incorporate NVM into your system.

After putting in NVM, it is advisable replace your shell’s configuration file (resembling `.bashrc`) to load NVM mechanically when opening a brand new terminal session. To do that, add the next traces to the tip of your configuration file, or create a brand new file if it doesn’t exist: export NVM_DIR=”$HOME/.nvm” [ -s “$NVM_DIR/nvm.sh” ] && . “$NVM_DIR/nvm.sh”

Save the file and restart your terminal. Now you can use NVM to handle your Node.js variations.

Choose and set up Node.js model

With NVM put in, now you can choose and set up a selected Node.js model. To put in the newest LTS model of Node.js, execute the command nvm set up –lts within the terminal.

To set the default model of Node.js for brand spanking new terminal periods, run the command nvm alias default <model>. This ensures that the specified model is used everytime you open a brand new terminal session.

Change between put in variations

NVM means that you can change between completely different put in Node.js variations simply. To modify to a selected Node.js model, execute the command nvm use <model> within the terminal.

For instance, to modify to model 14.19.0, kind nvm use 14.19.0. This command will activate the required model, permitting you to check your functions with completely different Node.js variations or use the options of a selected model.

Uninstalling Node.js from Ubuntu

When you ever must take away Node.js out of your Ubuntu system, the method will rely on the set up methodology you used. When you put in Node.js utilizing the apt package deal supervisor (utilizing Methodology 1 or Methodology 2 described above), you possibly can uninstall it by executing the command sudo apt take away nodejs within the terminal. This command will successfully take away the Node.js package deal out of your system.

When you put in Node.js utilizing NVM (Methodology 3), you possibly can uninstall a selected model by executing the command nvm uninstall <model>. Earlier than uninstalling the at present energetic model, it is advisable deactivate it by executing the command nvm deactivate. This can mean you can uninstall the energetic model with none points.

Abstract

On this information, we lined three completely different strategies for putting in Node.js on Ubuntu: utilizing the default Ubuntu repositories, the NodeSource repository, and NVM (Node Model Supervisor). Every methodology has its benefits and is appropriate for various eventualities.

FAQs About Putting in Node on Ubuntu

How do I set up Node.js on Ubuntu 20.04 LTS?

To put in Node.js 20 on Ubuntu 20.04 LTS, run the next instructions in a terminal window: sudo apt replace, sudo apt improve, sudo apt set up -y curl, curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -, and sudo apt set up -y nodejs. Confirm the model with node --version.

How can I confirm if I’ve sudo privileges?

To confirm sudo privileges, run the command sudo whoami and enter your password when prompted.

How can I change between completely different Node.js variations put in utilizing NVM?

To modify between Node.js variations put in utilizing NVM, merely execute the command nvm use <model> within the terminal. See our information to utilizing NVM right here.

How do I uninstall Node.js from my Ubuntu system?

To uninstall Node.js from Ubuntu, you should use both the apt package deal supervisor or NVM.



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments