Install NPM NodeJS Package Manager on Ubuntu

12/02/2020

How to Install and Use NPM (Node Package Manager) on Ubuntu 17.10

JavaScript is one of the most popular programming language in the world. No wonder that it’s so popular. It is the only programming language that web browsers understand. Every website in the world uses JavaScript to deliver interactive content to the visitors. Without JavaScript you would have a plain website and the page would reload every time you clicked. The web would not be what it is now.

But there is a problem with JavaScript. It runs on a Web Browser only. So on the server side you had to use something like PHP, Java, Python, Ruby and other programming languages. For a long time, developers wanted to use their favorite JavaScript on the server instead of PHP, Java and other programming languages. Node.js is one of the solutions for JavaScript on the server.

Node.js is very modular in nature. The language provides only the basic functionalities and it’s easily extended through the use of Node modules. There are a lot of Node modules that you can choose from. If you’re a developer, you should find some module or many that does what you want. But where do you find these modules? Well, there’s a repository where all the Node.js modules are kept. You can go to https://www.npmjs.com to search for Node.js modules.

Since Node.js is a modular language, and can be extended with Node.js modules, each of these modules depend on other Node.js modules. Installing Node.js modules manually is a tedious task and very impractical. This is where a Node Package Manager or NPM in short, comes in. With NPM, you can easily install, remove, update any module you want.

In this article, I am going to show you how to install and use NPM on Ubuntu 17.10 Artful Aardvark. Let’s get started.

Installing NPM:

NPM is available on the official package repository of Ubuntu 17.10 Artful Aardvark.

First update your package repository cache with the following command:

$ sudo apt-get update

Since NPM is a Node.js package manager, there’s no point in installing only NPM. So you can install Node.js and NPM together with the following command:

$ sudo apt-get install nodejs npm

Press ‘y’ and then <Enter> to continue.

Node.js and NPM should be installed.

Now run the following command to verify whether Node.js is working correctly.

$ node –version

You should see similar output as shown in the screenshot. It means Node.js is working correctly.

Now do the same for NPM with the following command:

$ npm –version

So NPM is working correctly as well.

Searching for Node.js Modules:

You can search for a Node.js module using NPM without going to https://www.npmjs.com

First update the NPM package repository cache with the following command:

$ npm update

Now to search for a Node.js module with NPM, run the following command:

$ npm search YOUR_QUERY

Let’s say you’re looking for a web framework; you would run the following command:

$ npm search “web framework”

You can see that search result is shown.

Installing Node.js Module using NPM:

You can install a Node.js module globally or locally. The difference is that, global node modules can be accessed like any other commands, but it’s not the case for locally installed modules. Soon you will see the difference.

I am going to install “express” module locally to show you how to install Node.js module with NPM.

Before I go any further, I am going to create a directory for my Node.js project and navigate to the directory.

$ mkdir node-demo && cd node-demo

Now to install ‘express’ using NPM, run the following command:

$ npm install express

‘express’ module should be installed and it should be stored in the ‘node_modules’ directory as shown in the screenshot below. When you install it locally, this subdirectory is created.

You can also install a module globally. Let’s say you want to install ‘express-generator’ globally, you would be running the following command:

$ sudo npm -g install express-generator

‘express-generator’ is installed.

Now ‘express-generator’ can be accessed from the command line.

Removing Node.js module with NPM:

You can remove a local Node.js module with NPM with the following command:

$ npm remove express

‘express’ is removed.

To remove ‘express-generator’ global Node.js module, you can run the following command:

$ sudo npm -g remove express-generator

‘express-generator’ is removed.

Listing installed Node.js Modules with NPM:

You can list locally installed Node.js Modules with the following command:

$ npm list

You can install globally installed Node.js Modules with the following command:

$ npm -g list

That’s how you install and use NPM on Ubuntu 17.10 Artful Aardvark. Thanks for reading this article.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Install NPM NodeJS Package Manager on Ubuntu

How to Install and Use NPM (Node Package Manager) on Ubuntu 17.10 JavaScript is one of the most popular programming language...
12/02/2020

Change Swap Size in Ubuntu

In the case of Linux, the swap file is an important part. It’s not a must-have option but having one is crucial for a...
29/12/2020

Install or Upgrade To Linux Kernel 4.9.2 on Ubuntu & Linux Mint

Greg Kroah-Hartman recently announced the stable release of Linux Kernel 4.9.2. This is the start of the stable review...
12/02/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?
27/05/2024