node.js - 无法在 ubuntu 16.04 中成功更新 npm

标签 node.js ubuntu npm

我已经尝试过这篇文章中建议的方法

How can I update Node.js and npm to the next versions?

1)npm更新-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) curl https://www.npmjs.com/install.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 容器中运行。这是码头文件:
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 ?

最佳答案

您可以为此使用 Node 版本管理器 (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 中的 Node docker

例如:

第一次拉:
docker pull node:6.11.5-wheezy

并将以下内容添加到 docker 文件中:
FROM node:6.11.5-wheezy

关于node.js - 无法在 ubuntu 16.04 中成功更新 npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47087100/

相关文章:

windows - 在 Linux 中使用 jenkins 和 electron-packager 为 windows 打包 Electron 应用程序

ios - 无法将用户从 iOS 客户端注册到 Ejabberd 服务器 - XMPP

node.js - 如何检查 Nodejs 中的 url(或 Web 服务)是否存在?

node.js - 如何在MERN中组织后端和前端的文件结构

web-services - Node.js 参数未正确传递给路由器

node.js - 如何使用 isomorphic-fetch 使用 application/x-www-form-urlencoded header 和 URLSearchParams 进行 POST

node.js - 为什么 `yarn upgrade my_package` 升级时不考虑 package.json 中的版本

javascript - node.js TypeError : path must be absolute or specify root to res. sendFile [无法解析JSON]

c++ - Boost Spirit代码,用msvc编译,用gcc编译报错

json - 如何批量插入600MB大json文件到elasticsearch?