Web Development: The Basics
This means you also already have all the tools you need to build out your ideas. Plus, you don’t have to worry about writing the same app in many different languages to accommodate multiple devices.
How to Install NPM on Linux Mint
Update Your Current Package List
We will start by updating our current package list with the apt update.
$ sudo apt update
Install node.js Using apt
The nodejs package is provided in Mint’s official repositories, so install it using apt.
$ sudo apt install nodejs -y
We can confirm that
nodejs was successfully installed by checking the version. This can be done by typing in the following command:
$ nodejs --version v12.22.9
Install npm Using apt
The npm package is provided in Mint’s official repositories, so simply install it using apt.
$ sudo apt install npm -y
The installation may take minutes, depending on your internet connection.
Once again, we can check the version to ensure npm was successfully installed.
$ npm --version 8.5.1
How to Use npm
Using npm is very easy, and the syntax is similar to the apt package manager. Do this by typing the following command:
$ npm --help
Looking at the help page, we can see that packages are installed by typing
npm install in the terminal.
For more details, we can also look at the manual page for npm by typing man npm into the terminal.
Installing Packages Locally and Globally
There are two ways packages can be installed using npm. The way that we have already shown is how you install packages locally. Packages should be installed locally if you intend to use them for a specific project only & don’t want to have them in your other projects.
Here is an example of installing the chalk package locally:
$ npm install chalk
To install packages locally, navigate to the project directory and install the packages using npm install. If you would like a package installed globally to have it accessible from any project, you simply need to add the
It’s important to note that when installing packages globally, you will have to prefix the command with the sudo command since the global packages are installed in the
/usr/local/lib/node_modules directory by default.
Installing the chalk package globally would look something like this:
$ sudo npm install -g chalk
Removing npm Packages
To remove an npm package, simply run the npm uninstall command. Once again, if you want to remove a local package, navigate to the project directory where the package is installed and run the command.
$ npm uninstall chalk
And if you would like to remove a global package, add the
–global flag and run the command with sudo privileges.
$ sudo npm -g uninstall chalk
List Installed packages
To list all installed packages, use the
npm ll command. Same as before, if you want to list the locally installed packages, navigate to the project directory and run this command:
$ npm ll
And if you want to list all the globally installed packages, add the
-g flag again. However, this time we won’t need sudo since we are only reading from the directory and not writing to it.
$ npm -g ll
Remove node.js and npm
If you want to remove
npm from your computer, you can run the following command:
$ sudo apt purge --autoremove npm nodejs
Remember that this will not delete your packages installed with npm, so if you want to remove everything, make sure to uninstall the packages you installed with npm and then remove them.
If you’re looking to build web apps, npm is a powerful tool you should consider. With over 1.3 million packages in its repositories, npm can save you time and make it easier to focus on building out your ideas straight away instead of having to worry about building the tools first.
If this guide helped you, please share it.