I just installed node on Ubuntu 22.04 via snap using the following command, per GitHub page instructions:
# snap install node --classic
Afterwards, node and npm both reported their versions successfully.
# node --version
v18.16.0
# npm --version
9.5.1
As soon as I drop out of root though, only node remains available to me as a non-privileged user:
$ node --version
v18.16.0
$ npm --version
-bash: /usr/bin/npm: No such file or directory
Is this expected behaviour? How can I make npm available generally?
For what its worth, here is the content of /snap/bin:
$ ls -l /snap/bin
total 0
lrwxrwxrwx 1 root root 13 Jun 1 04:51 amazon-ssm-agent.ssm-cli -> /usr/bin/snap
lrwxrwxrwx 1 root root 7 Jun 1 04:51 lxc -> lxd.lxc
lrwxrwxrwx 1 root root 13 Jun 1 04:51 lxd -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 04:51 lxd.benchmark -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 04:51 lxd.buginfo -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 04:51 lxd.check-kernel -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 04:51 lxd.lxc -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 04:51 lxd.lxc-to-lxd -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 04:51 lxd.migrate -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 11:52 node -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 11:52 node.npm -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 11:52 node.npx -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 11:52 node.yarn -> /usr/bin/snap
lrwxrwxrwx 1 root root 13 Jun 1 11:52 node.yarnpkg -> /usr/bin/snap
lrwxrwxrwx 1 root root 8 Jun 1 11:52 npm -> node.npm
lrwxrwxrwx 1 root root 8 Jun 1 11:52 npx -> node.npx
lrwxrwxrwx 1 root root 24 Jun 1 04:51 ssm-cli -> amazon-ssm-agent.ssm-cli
lrwxrwxrwx 1 root root 9 Jun 1 11:52 yarn -> node.yarn
lrwxrwxrwx 1 root root 12 Jun 1 11:52 yarnpkg -> node.yarnpkg
Note that the nodejs
and npm
packages were previously installed but then removed via apt
before trying to use snap. Perhaps some hangover from that is causing this issue?
I have the same issue.
TL;DR : I removed node snap package (which removes npm snap package too) and installed nvm
, then nvm install node
. Everything works like a charm.
To get into the details, I think it would also work to change PATH but I'm not sure it is a recommended way to fix this issue. nvm installation procedure is pretty straightforward.