I have tried the suggested methods in this post
How can I update Node.js and npm to the next versions?
1) npm update -g npm
npm update -g npm
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
/usr/bin/npx -> /usr/lib/node_modules/npm/bin/npx-cli.js
- asap@2.0.5 node_modules/npm/node_modules/asap
- fstream@1.0.10 node_modules/npm/node_modules/fstream
- balanced-match@0.4.2 node_modules/npm/node_modules/fstream-npm/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match
- concat-map@0.0.1 node_modules/npm/node_modules/fstream-npm/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map
- brace-expansion@1.1.6 node_modules/npm/node_modules/fstream-npm/node_modules/fstream-ignore/node_modules/minimatch/node_modules/brace-expansion
...
- realize-package-specifier@3.0.3 node_modules/npm/node_modules/realize-package-specifier
/usr/lib
`-- npm@5.5.1
But when I tried npm --version
it fails with this error message:
# npm --version
module.js:471
throw err;
^
Error: Cannot find module 'process-nextick-args'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
2) curl https://www.npmjs.com/install.sh | sh
# curl https://www.npmjs.com/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6255 100 6255 0 0 6728 0 --:--:-- --:--:-- --:--:-- 6725
tar=/bin/tar
version:
tar (GNU tar) 1.28
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by John Gilmore and Jay Fenlason.
install npm@latest
fetching: https://registry.npmjs.org/npm/-/npm-5.5.1.tgz
module.js:471
throw err;
^
Error: Cannot find module '/tmp/npm.18/package/bin/read-package-json.js'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:383:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:496:3
removed 266 packages in 5.41s
/usr/bin/npx -> /usr/lib/node_modules/npm/bin/npx-cli.js
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
+ npm@5.5.1
added 1 package in 1.642s
It worked
But the npm
command is not available in the system. It seems the files are not installed at all
# ls -l /usr/bin/npm
lrwxrwxrwx 1 root root 38 Nov 3 01:26 /usr/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js
# ls /usr/lib/node_modules/npm/bin/npm-cli.js
ls: cannot access '/usr/lib/node_modules/npm/bin/npm-cli.js': No such file or directory
My ubuntu is running in a docker container. Here is the dockerfile:
FROM ubuntu:16.04
RUN apt-get update --fix-missing && apt-get install -y vim libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
# RUN apt-get install -y npm
RUN update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
So what is the most up-to-date way to upgrade npm
?