为什么 Debian/Ubuntu 上只有过时版本的 NPM 可用?
Why only outdated version of NPM is available on Debian/Ubuntu?
我正在使用基于 Debian/Ubuntu 的发行版(具体来说,AWS Ubuntu 16.04)并尝试通过 apt-get
安装 NPM。
我的 Angular 2 应用程序需要比 NPM 3.9.x 更高的版本,但是正在安装的默认版本是 3.5.2 使用 sudo apt-get install npm
on AWS Ubuntu 16.04。我正在尝试更新 NPM,但它没有从 3.5.2 升级到 4.6.1(最新)。
如何 install/update NPM 以便获得最新版本?
您将获得 npm 3.5.2 版,因为那是 repositories 中的版本。 Debian 和 Ubuntu 在跟上 Node 和 npm 的快速开发速度方面通常 很糟糕 ,因此您经常会发现软件包已过时,而且并不多给你用。
一些 Debian 发行版(例如 Jessie)只有 npm v1.4.21,这更过时了。顺便说一下,Debian Jessie 是 Raspbian RPi 发行版 Jessie 所基于的版本。
而是遵循 the instructions given on the Node.js website:
Node.js is available from the NodeSource Debian and Ubuntu binary distributions repository (formerly Chris Lea's Launchpad PPA). Support for this repository, along with its scripts, can be found on GitHub at nodesource/distributions.
NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 6.x on older distros.
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
Alternatively, for Node.js v7:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
NodeSource提供的nodejs
包中包含npm。只需安装它,您就可以使用最新版本了。
在您的服务器 bash 上输入 'hash -r'。
然后再次检查您的'npm -v'
sudo npm install -g npm
对我有用,然后我需要@StefanBob
提供的答案
我已经阅读了这个答案,它在这个问题上对我有帮助:
https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation
希望对你也有帮助。
$ sudo apt-get install npm
(...apt installation of npm was successful...)
$ npm -v
3.5.2
$ command -v npm
/usr/bin/npm
$ sudo npm install -g npm
(...npm installation of npm was successful...so far, so good)
之后,只需重新启动 bash 或按照 krubo 的步骤。
升级 npm:
$ sudo npm install -g npm@latest
$ reboot
$ npm -v
完成安装:
$ sudo apt install nodejs
$ sudo apt install npm
$ npm -v
npm 版本:3.5.2
然后升级:
$ npm install -g npm@latest
$ reboot
$ npm -v
试试这个
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
的解决方案对我有用。
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
但是 nodejs 包安装在不同的路径,我手动删除了旧包(在 /usr/bin/
中)并添加了一个指向新包的符号链接(在 /usr/local/bin
中)。
sudo rm /usr/bin/node
sudo ln -s /usr/local/node /usr/bin/node
这是 运行 命令的初始打印输出。 npm
版本从 5.8.0
更新到 8.1.2
。但是即使在使用 hash -r
.
重新启动后,nodejs
版本仍保持在 10.24.0
我正在使用基于 Debian/Ubuntu 的发行版(具体来说,AWS Ubuntu 16.04)并尝试通过 apt-get
安装 NPM。
我的 Angular 2 应用程序需要比 NPM 3.9.x 更高的版本,但是正在安装的默认版本是 3.5.2 使用 sudo apt-get install npm
on AWS Ubuntu 16.04。我正在尝试更新 NPM,但它没有从 3.5.2 升级到 4.6.1(最新)。
如何 install/update NPM 以便获得最新版本?
您将获得 npm 3.5.2 版,因为那是 repositories 中的版本。 Debian 和 Ubuntu 在跟上 Node 和 npm 的快速开发速度方面通常 很糟糕 ,因此您经常会发现软件包已过时,而且并不多给你用。
一些 Debian 发行版(例如 Jessie)只有 npm v1.4.21,这更过时了。顺便说一下,Debian Jessie 是 Raspbian RPi 发行版 Jessie 所基于的版本。
而是遵循 the instructions given on the Node.js website:
Node.js is available from the NodeSource Debian and Ubuntu binary distributions repository (formerly Chris Lea's Launchpad PPA). Support for this repository, along with its scripts, can be found on GitHub at nodesource/distributions.
NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 6.x on older distros.
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install -y nodejs
Alternatively, for Node.js v7:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - sudo apt-get install -y nodejs
NodeSource提供的nodejs
包中包含npm。只需安装它,您就可以使用最新版本了。
在您的服务器 bash 上输入 'hash -r'。
然后再次检查您的'npm -v'
sudo npm install -g npm
对我有用,然后我需要@StefanBob
提供的答案我已经阅读了这个答案,它在这个问题上对我有帮助:
https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation
希望对你也有帮助。
$ sudo apt-get install npm
(...apt installation of npm was successful...)
$ npm -v
3.5.2
$ command -v npm
/usr/bin/npm
$ sudo npm install -g npm
(...npm installation of npm was successful...so far, so good)
之后,只需重新启动 bash 或按照 krubo 的步骤。
升级 npm:
$ sudo npm install -g npm@latest
$ reboot
$ npm -v
完成安装:
$ sudo apt install nodejs
$ sudo apt install npm
$ npm -v
npm 版本:3.5.2
然后升级:
$ npm install -g npm@latest
$ reboot
$ npm -v
试试这个
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo npm cache clean -f sudo npm install -g n sudo n stable
但是 nodejs 包安装在不同的路径,我手动删除了旧包(在 /usr/bin/
中)并添加了一个指向新包的符号链接(在 /usr/local/bin
中)。
sudo rm /usr/bin/node
sudo ln -s /usr/local/node /usr/bin/node
这是 运行 命令的初始打印输出。 npm
版本从 5.8.0
更新到 8.1.2
。但是即使在使用 hash -r
.
nodejs
版本仍保持在 10.24.0