The wget command can be used to download the Node.js installation tar from https://nodejs.org/en/download to your Linux system that wil be running Node.js. This will download a file such as node-v20.10.0-linux-x64.tar.xz.
wget https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz
Then use the tar command to extract the file. In this example, Node.js will be extracted to the /usr/local/bin directory.
tar -xpf node-v20.10.0-linux-x64.tar.xz --directory /usr/local/bin/
There should now be a directory such as /usr/local/bin/node-v20.10.0-linux-x64
You can now delete the tar.xz file you downloaded.
rm node-v20.10.0-linux-x64.tar.xz
Let's create a symbolic link from /usr/bin/node to /usr/local/nodejs/node-v20.10.0-linux-x64/bin/node (in this example) so that the node command is in our $PATH (since CLIs in the /usr/bin directory should be in our $PATH) so that we can just use the node command and not the full path to the node CLI.
ln -s /usr/local/bin/node-v20.10.0-linux-x64/bin/node /usr/local/bin/node
ln -s /usr/local/bin/node-v20.10.0-linux-x64/bin/node /usr/bin/node
Let's also create a symbolic link from /usr/bin/npm to /usr/local/nodejs/node-v20.10.0-linux-x64/lib/node_modules/npm/bin/npm-cli.js (in this example).
ln -s /usr/local/bin/node-v20.10.0-linux-x64/lib/node_modules/npm/bin/npm-cli.js /usr/bin/npm
ln -s /usr/local/bin/node-v20.10.0-linux-x64/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
And npx too.
ln -s /usr/local/bin/node-v20.10.0-linux-x64/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
ln -s /usr/local/bin/node-v20.10.0-linux-x64/lib/node_modules/npm/bin/npx-cli.js /usr/bin/npx
You should now be able to use the npm command, which is located at /opt/nodejs/bin/npm.
~]# npm --help
Usage: npm <command>
where <command> is one of:
access, adduser, audit, bin, bugs, c, cache, ci, cit,
clean-install, clean-install-test, completion, config,
create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
edit, explore, fund, get, help, help-search, hook, i, init,
install, install-ci-test, install-test, it, link, list, ln,
login, logout, ls, org, outdated, owner, pack, ping, prefix,
profile, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, team, test, token, tst, un,
uninstall, unpublish, unstar, up, update, v, version, view,
whoami
npm <command> -h quick help on <command>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
/root/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm@6.14.13 /opt/nodejs/lib/node_modules/npm
Did you find this article helpful?
If so, consider buying me a coffee over at