Install the nodejs package. There are LTS releases, too:
- nodejs-lts-hydrogen - For 18.X version
- nodejs-lts-gallium - For 16.X version
- nodejs-lts-fermium - For 14.X version
It is not uncommon to need or desire to work in different versions of nodejs. A preferred method among node users is to use NVM (Node Version Manager). nvmAUR allows for cheap and easy alternative installs.
You can set it up by adding this to your shell's startup file:
# Set up Node Version Manager source /usr/share/nvm/init-nvm.sh
Usage is well documented on the project's GitHub but is as simple as:
$ nvm install 8.0 Downloading and installing node v8.0.0... [..] $ nvm use 8.0 Now using node v8.0.0 (npm v5.0.0)
If you decide to use nvmAUR, previously it was suggested to use
nodejs-fake package from AUR. Which is now deleted.
Suggested way is to use
--assume-installed nodejs=<version>, as per the manual pacman(8) § TRANSACTION OPTIONS (APPLY TO -S, -R AND -U).
If you want to run `nvm use` automatically every time there is a .nvmrc file on the directory, add this in
Node Packaged Modules
npm is the official package manager for node.js. It can be installed with the npm package.
Managing packages with npm
Any package can be installed using:
$ npm install packageName
This command installs the package in the current directory under
node_modules and executables under
For a system-wide installation global switch
-g can be used:
# npm -g install packageName
By default this command installs the package under
/usr/lib/node_modules/npm and requires root privileges to do so.
Allow user-wide installations
To allow global package installations for the current user, set the
npm_config_prefix environment variable. This is used by both npm and yarn.
PATH="$HOME/.local/bin:$PATH" export npm_config_prefix="$HOME/.local"
Re-login or source to update changes.
You can also specify the
--prefix parameter for
npm install. However, this is not recommended, since you will need to add it every time you install a global package.
$ npm -g install packageName --prefix ~/.local
Another option is to set
prefix field in
$HOME/.npmrc. This achieves the same effect as using
npm_config_prefix="$HOME/.local" in one's
$ npm set prefix="$HOME/.local"
Updating packages is as simple as
$ npm update packageName
For the case of globally installed packages (
# npm update -g packageName
prefixis set to a user-writable directory
Updating all packages
However, sometimes you may just wish to update all packages, either locally or globally. Leaving off the packageName
npm will attempt to update all packages
$ npm update
or add the
-g flag to update globally installed packages
# npm update -g
To remove a package installed with the
-g switch simply use:
# npm -g uninstall packageName
to remove a local package drop the switch and run:
$ npm uninstall packageName
To show a tree view of the installed globally packages use:
$ npm -g list
This tree is often quite deep. To only display the top level packages use:
$ npm list --depth=0
To display obsolete packages that may need to be updated:
$ npm outdated
Managing packages with pacman
Some node.js packages can be found in Arch User Repository with the name
npm help does not display documentation
npm help topic may not display the documentation for topic. Instead, use
man npm-topic. For example:
$ npm help install Top hits for "install" ... $ man npm-install ... shows the documentation for the npm install subcommand
This is a bug with Arch's npm package.
In case of errors like
gyp WARN EACCES user "root" does not have permission to access the ... dir,
--unsafe-perm option might help:
# npm install --unsafe-perm -g node-inspector
Cannot find module ... errors
Since npm 5.x.x. package-lock.json file is generated along with the package.json file. Conflictions may arise when the two files refer to different package versions. A temporary method to solving this problem has been:
$ rm package-lock.json $ npm install
However, fixes were made after npm 5.1.0 or above. For further information, see: missing dependencies
For further information on Node.js and the use of its official package manager NPM you may wish to consult the following external resources
- Node.js documentation
- NPM documentation
- IRC channel #node.js on Libera Chat