我在这篇文章中尝试了建议的方法
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
但是当我尝试npm --version
时,它失败并显示以下错误信息:
# 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)卷曲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
但npm
命令在系统中不可用。似乎文件根本没有安装
# 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
我的ubuntu在docker容器中运行。这是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
那么升级npm
的最新方法是什么?
答案 0 :(得分:1)
您可以使用节点版本管理器(NVM)。尝试使用以下命令。使用node时我遇到了apt-get的多个问题,但是下面总是有效。
//This will install npm v5.4, this might break if you're using node 4.5 and 4.6
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
//To uninstall a node version
nvm uninstall <current version>
nvm install 8.5.0
nvm use 8.5.0
//check with
node -v
如果您将它与docker一起使用,最简单的方法是直接使用docker hub中的节点docker
例如:
首先拉:
docker pull node:6.11.5-wheezy
并将以下内容添加到docker文件中:
FROM node:6.11.5-wheezy