【问题标题】:Why node and npm version differs?为什么 node 和 npm 版本不同?
【发布时间】:2021-10-31 12:07:19
【问题描述】:

看,我安装了最新的节点版本

node -v   // I get v14.15.0

然后我为一个小项目运行npm init。我还创建了一个 index.js 文件,代码如下

console.lo("Hello") 

显然有错别字,应该是console.log("Hello"),但我这样做是为了得到项目使用的node和npm版本。

npm ERR! Linux 5.4.0-81-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "npm@next"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! path /usr/local/lib/node_modules/.staging/@gar/promisify-ebaab35a
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename

它使用的是旧版本,但我想要最新的。我没有强迫使用旧版本 那么我如何 npm init 但使用最新版本的 node 和 npm。

另外,当我尝试使用 sudo npm install -g npm@next 更新 npm 时,我收到此错误

npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@gar/promisify-ebaab35a' -> '/usr/local/lib/node_modules/npm/node_modules/@gar/promisify'
npm ERR! enoent ENOENT: no such file or directory, rename '/usr/local/lib/node_modules/.staging/@gar/promisify-ebaab35a' -> '/usr/local/lib/node_modules/npm/node_modules/@gar/promisify'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! Please include the following file with any support request:
npm ERR!     /home/braulio/npm-debug.log
npm ERR! code 1

我认为 npm 正在强制 node 使用 v8.10,所以也许在我不更新 npm 之前,node 不会。我该如何解决这个问题?

【问题讨论】:

    标签: node.js npm


    【解决方案1】:

    您可以下载 node.js linux tarball 并解压缩它们,而不是将 node 安装到 /usr/bin/node 和 npm 到 /usr/bin/npm,然后在 bin 目录中可以使用 node/npm 二进制文件。然后将当前终端的 $PATH 修改为以下格式:

    export $PATH=/opt/node-vxx.xx.x/bin/:$PATH
    which node
    node -v
    which npm 
    npm -v
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 2022-06-22
      • 2018-03-10
      • 2021-07-21
      • 1970-01-01
      相关资源
      最近更新 更多