Home  >  Article  >  System Tutorial  >  Node.js and npm in Linux: Essential Tools for JavaScript Developers

Node.js and npm in Linux: Essential Tools for JavaScript Developers

王林
王林forward
2024-02-09 19:36:24867browse

JavaScript is a widely used programming language that can run in the browser or on the server side. To run JavaScript on the server side, you need a JavaScript runtime environment, and Node.js is the most popular one. Node.js is built on Chrome's V8 engine, which lets you write high-performance, event-driven, asynchronous web applications using JavaScript. npm is the default package manager for Node.js, which allows you to easily install, update, and remove various JavaScript modules and packages.

In this article, we will teach you how to install the latest Node.js and npm in Linux, and how to use them to create and run your JavaScript applications. We'll cover three different installation methods: using apt to install nodejs packages from Ubuntu's default repository; using apt to install a specific version of nodejs package from an alternative PPA repository; installing nvm, the Node version manager, and using it to install and manage multiple versions of Node.js. Depending on your needs and preferences, you can choose one of these methods to start your JavaScript development journey.

Nodejs is a lightweight and efficient JavaScript platform built on Chrome's V8 JavaScript engine, and NPM is the default NodeJS package manager. You can use it to build scalable web applications.

This article will introduce:

  • How to install Node.js 14 in CentOS, RHEL and Fedora
  • How to install Node.js 14 in Debian, Ubuntu and Linux Mint

How to install Node.js 14 in CentOS, RHEL and Fedora

The latest versions of Node.js and NPM are available from the official NodeSource Enterprise Linux repository, which is maintained by the Nodejs website and you need to add it to your system to install the latest Nodejs and NPM packages.

IMPORTANT: If you are running RHEL 6 or an older version of CentOS 6, you may want to read about running Node.js on older distributions.

Installing NodeJS 14.x in RHEL, CentOS and Fedora

To add a repository for the latest version of Node.js 14.x, use the following command as a superuser or non-superuser.

————– As root user ————–
# curl -sL https://rpm.nodesource.com/setup_14.x | bash –

————– User with root privileges ————–
$ curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash –

Installing NodeJS 12.x on RHEL, CentOS and Fedora

If you want to install NodeJS 12.x, please add the following repository.

————– As root user ————–
# curl -sL https://rpm.nodesource.com/setup_12.x | bash –

————– User with root privileges ————–
$ curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash –

Installing NodeJS 10.x on RHEL, CentOS and Fedora

If you want to install NodeJS 10.x, please add the following repository.

————– As root user ————–
# curl -sL https://rpm.nodesource.com/setup_10.x | bash –

————– User with root privileges ————–
$ curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash –

Next, you can now install Nodejs and NPM on your system using the following commands:

# yum -y install nodejs
or
# dnf -y install nodejs

Optional: There are development tools, such as gcc-c, that you need to have installed on your system in order to build native plugins from npm.

# yum install gcc-c make
or
# yum groupinstall ‘Development Tools’

How to Install Node.js 14 in Debian, Ubuntu and Linux Mint

The latest versions of Node.js and NPM are also available from the official NodeSource Enterprise Linux repository, which is maintained by the Nodejs website and you need to add it to your system to install the latest Nodejs and NPM packages.

Installing NodeJS 14.x in Debian, Ubuntu and Linux Mint

——-On Ubuntu and Linux Mint ——-

sudo apt-get install -y nodejs

——- On Debian ——-
# curl -sL https://deb.nodesource.com/setup_14.x | bash –
# apt-get install -y nodejs

Installing NodeJS 12.x in Debian, Ubuntu and Linux Mint

——-On Ubuntu and Linux Mint ——-

sudo apt-get install -y nodejs

——- On Debian ——-
# curl -sL https://deb.nodesource.com/setup_12.x | bash –
# apt-get install -y nodejs

Installing NodeJS 10.x in Debian, Ubuntu and Linux Mint

——-On Ubuntu and Linux Mint——-

sudo apt-get install -y nodejs

——- On Debian ——-
# curl -sL https://deb.nodesource.com/setup_10.x | bash –
# apt-get install -y nodejs

Optional: There are development tools, such as gcc-c, that you need to have installed on your system in order to build native plugins from npm.

$ sudo apt-get install -y build-essential

Testing the latest Node.js and NPM in Linux

For a simple test of nodejs and NPM, you can check the version installed on your system using the following command:

On RHEL, CentOS and Fedora

# node –version
# npm –version

On Debian, Ubuntu and Linux Mint

npm –version

Node.js and npm in Linux: Essential Tools for JavaScript Developers

That’s it, Nodejs and NPM are now installed and ready to use on your system.

I believe these are simple steps, but if you run into problems, let us know and we'll find a way to help you. I hope you find this guide helpful and always remember to stay connected to linuxmi.com.

The above is the detailed content of Node.js and npm in Linux: Essential Tools for JavaScript Developers. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lxlinux.net. If there is any infringement, please contact admin@php.cn delete