3.7 C
New York
Friday, January 12, 2024

Set up Node.js on Ubuntu — SitePoint


Node.js has revolutionized the best way we construct net purposes by enabling builders to create scalable community purposes utilizing JavaScript on the server facet. 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 stipulations, organising your Node.js atmosphere, and uninstalling Node.js if wanted.

Desk of Contents

Key Takeaways

  • Discover ways to set up Node.js and npm on Ubuntu utilizing the default repository, NodeSource repository or NVM (Node Model Supervisor).
  • Arrange your atmosphere by making a mission listing, initializing a mission and operating easy packages.
  • Uninstall Node.js from Ubuntu with both apt bundle supervisor or NVM relying on set up technique used.

Understanding Node.js

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

Furthermore, Node.js gives quite a few advantages, corresponding to scalability, fast growth price, and a sturdy neighborhood. With an ever-growing variety of packages and modules obtainable, Node.js has turn into 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 could have sudo privileges, which you’ll confirm by executing the command sudo whoami and coming 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 beneficial 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 entails utilizing the default Ubuntu repositories. This strategy is simple and appropriate for many customers. Nevertheless, 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 bundle lists, set up Node.js and npm, and confirm the set up.

Replace bundle lists

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

Set up Node.js and npm

To put in Node.js and npm utilizing the apt bundle 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’s good to set up npm, the bundle 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 purposes.

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 technique entails putting in Node.js and npm from the NodeSource repository. This technique 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 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 make sure 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 will be discovered on the NodeSource repository’s GitHub web page. This may obtain and run the set up script, incorporating the NodeSource repository into your system.

As soon as the repository is added, you may 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 particular launch, relying in your wants.

Affirm set up

Upon putting in Node.js and npm from the NodeSource repository, you should definitely 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 technique is good for customers who want to change between Node.js variations typically or need to check their purposes with completely different variations. We’ve 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 swap between put in variations.

Set up NVM

To put in NVM, it’s good to 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 may incorporate NVM into your system.

After putting in NVM, it’s good to replace your shell’s configuration file (corresponding to `.bashrc`) to load NVM mechanically when opening a brand new terminal session. To do that, add the next traces to the top 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 particular 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 new terminal classes, run the command nvm alias default <model>. This ensures that the specified model is used everytime you open a brand new terminal session.

Swap between put in variations

NVM lets you swap between completely different put in Node.js variations simply. To change to a particular Node.js model, execute the command nvm use <model> within the terminal.

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

Uninstalling Node.js from Ubuntu

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

In the event you put in Node.js utilizing NVM (Methodology 3), you may uninstall a particular model by executing the command nvm uninstall <model>. Earlier than uninstalling the at present energetic model, it’s good to deactivate it by executing the command nvm deactivate. This may will let you 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 technique 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 swap between completely different Node.js variations put in utilizing NVM?

To change 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 bundle supervisor or NVM.



Supply hyperlink

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles