Node.js has revolutionized the way in which we construct internet functions by enabling builders to create scalable community functions utilizing JavaScript on the server aspect. To harness the complete 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 well-liked Linux distribution, utilizing three completely different strategies. We’ll additionally cowl conditions, establishing your Node.js setting, 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 setting by making a mission listing, initializing a mission and working easy applications.
  • Uninstall Node.js from Ubuntu with both apt package deal supervisor or NVM relying on set up technique used.

Understanding Node.js

Node.js is a server-side JavaScript runtime setting that permits builders to construct scalable internet 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 internet functions. Putting in Node.js in your internet server lets you leverage these options, key to creating state-of-the-art internet functions.

Furthermore, Node.js presents quite a few advantages, reminiscent of scalability, fast improvement charge, and a strong group. With an ever-growing variety of packages and modules out there, Node.js has grow to be an indispensable software for internet builders worldwide.

Stipulations for Putting in Node.js on Ubuntu

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

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

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 advisable for customers who require frequent switching between Node.js variations, because it lets you handle a number of variations simply.

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

The primary technique to put in Node.js and npm includes utilizing the default Ubuntu repositories. This method is easy and appropriate for many customers. Nonetheless, it might 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

Be certain that to replace the package deal lists within the terminal previous to putting in Node.js and npm. This ensures that you simply get the most recent 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’ll be able to 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 simple and safe.

Subsequent, you should 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 working your JavaScript code and creating internet 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 test 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 accurately, and you can begin working your JavaScript code.

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

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

The NodeSource repository is a Private Bundle 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 on your Ubuntu model, which might be discovered on the NodeSource repository’s GitHub web page. It will obtain and run the set up script, incorporating the NodeSource repository into your system.

As soon as the repository is added, you’ll be able to 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 most recent model or a selected launch, relying in your wants.

Affirm set up

Upon putting in Node.js and npm from the NodeSource repository, make sure 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 working your JavaScript code.

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

NVM is a flexible software for Node.js model administration, permitting you to put in and handle a number of Node.js variations simply. This technique is right for customers who want to change between Node.js variations usually or wish to take a look at their functions with completely different variations. Now we have a complete guide to using NVM 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, you should observe these steps:

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

After putting in NVM, you should replace your shell’s configuration file (reminiscent of `.bashrc`) to load NVM mechanically when opening a brand new terminal session. To do that, add the next strains 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 most recent 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 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 lets you 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 change to model 14.19.0, sort nvm use 14.19.0. This command will activate the desired 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

If you happen to ever must take away Node.js out of your Ubuntu system, the method will depend upon the set up technique you used. If you happen to put in Node.js utilizing the apt package deal supervisor (utilizing Methodology 1 or Methodology 2 described above), you’ll be able to 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.

If you happen to put in Node.js utilizing NVM (Methodology 3), you’ll be able to uninstall a selected model by executing the command nvm uninstall <model>. Earlier than uninstalling the presently energetic model, you should deactivate it by executing the command nvm deactivate. It will let you uninstall the energetic model with none points.

Abstract

On this information, we coated 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 technique has its benefits and is appropriate for various situations.

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 guide to using NVM 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.