当前位置: 首页>>技术教程>>正文


为什么在Ubuntu 16.04上安装节点6.x实际安装节点4.2.6?

, ,

问题描述

这些是我在Ubuntu 16.04上安装节点的步骤:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs 
sudo apt-get install -y npm

这是官方说明:

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

执行此操作后,运行nodejs --version将返回v4.2.6

当我使用setup_6.x时,我假设将安装一个以6开头的版本?

我想也许setup_6.x应该是setup_6.2.1,但该页面返回404,请参阅:

https://deb.nodesource.com/setup_6.x(那里有一个页面)

https://deb.nodesource.com/setup_6.2.1(返回404)

如何在Ubuntu 16.04上安装最新的稳定版节点?

编辑:

这些是运行sudo apt-get install -y nodejs后的结果:

sudo apt-get install -y nodejs 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gyp libboost-python1.58.0 libjs-inherits libjs-node-uuid libjs-underscore
  libssl-dev libssl-doc libuv1-dev linux-headers-4.4.0-18
  linux-headers-4.4.0-18-generic linux-headers-4.4.0-21
  linux-headers-4.4.0-21-generic linux-image-4.4.0-18-generic
  linux-image-4.4.0-21-generic linux-image-extra-4.4.0-18-generic
  linux-image-extra-4.4.0-21-generic linux-signed-image-4.4.0-18-generic
  linux-signed-image-4.4.0-21-generic python-configobj python-pycurl
  python-pyexiv2 python-pyexiv2-doc
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  nodejs
0 to upgrade, 1 to newly install, 0 to remove and 0 not to upgrade.
Need to get 0 B/3,162 kB of archives.
After this operation, 13.2 MB of additional disk space will be used.
Selecting previously unselected package nodejs.
(Reading database ... 329473 files and directories currently installed.)
Preparing to unpack .../nodejs_4.2.6~dfsg-1ubuntu4_amd64.deb ...
Unpacking nodejs (4.2.6~dfsg-1ubuntu4) ...
Processing triggers for doc-base (0.10.7) ...
Processing 1 added doc-base file...
Registering documents with scrollkeeper...
Processing triggers for man-db (2.7.5-1) ...
Setting up nodejs (4.2.6~dfsg-1ubuntu4) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode

编辑:

apt-cache policy nodejs的结果:

apt-cache policy nodejs
nodejs:
  Installed: 4.2.6~dfsg-1ubuntu4
  Candidate: 4.2.6~dfsg-1ubuntu4
  Version table:
 *** 4.2.6~dfsg-1ubuntu4 500
        500 http://au.archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
        100 /var/lib/dpkg/status

最佳解决方案

核心原因是安装脚本无法正常运行。因此,由于来自支持此功能的OP的更新数据,apt从未看到来自NodeSource存储库的数据,因为脚本未正确配置它。

因此,脚本可能没有找到您的发行版,或者在配置存储库时可能已经搞砸了,或者可能存在网络中断,或者其中任何一个原因导致其中断并且没有完成其工作。

您看到安装版本4.x的事实意味着脚本无法正常工作,因此脚本不一定有问题。这只是意味着我们必须以更难的方式做到这一点。

I should point out: the script doesn’t actually do any installing – all it does is determine the Debian/Ubuntu version you’re on, and configure the repository for it to get data from. The installation part is actually the sudo apt-get install step you ran by hand.


我们可以执行脚本执行old-school方式的操作,而不是依赖脚本:手动,自己,设置存储库配置并安装NodeJS。

这是使这项工作的手动方式,它基本上是脚本的功能(步骤4除外,这是为了确保您获得准确的版本数据):

  1. 创建一个新文件:/etc/apt/sources.list.d/nodesource.list

    您需要使用sudo创建此文件,但在创建文件时,请将其放入其中:

    deb https://deb.nodesource.com/node_6.x xenial main
    deb-src https://deb.nodesource.com/node_6.x xenial main
    

    然后,保存文件。 (对于较新的Node版本,将node_6.x替换为node_7.xnode_8.x等)

  2. 从Nodesource下载存储库的GPG签名密钥。否则,您可能会在apt-get update中收到NO_PUBKEY错误:

    curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
    
  3. 手动运行sudo apt-get update。这将刷新来自nodesource repo的数据,因此apt知道存在更新的版本。如果您收到NO_PUBKEY GPG错误,请返回步骤2

  4. 检查apt-cache policy nodejs输出。

    这不是由脚本完成的,但是你想确保在输出中看到一个类似这样的条目(尽管如果你不使用6.x作为版本字符串,版本可能会有所不同;我们唯一的事情是关心的是通过nodesource提供的新版本号:

    Version table:
        6.2.1-1nodesource1~xenial1 500
           500 https://deb.nodesource.com/node_6.x xenial/main amd64 Packages
        4.2.6~dfsg-1ubuntu4 500
           500 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
    

    如果您没有看到这样的条目,只看到4.2.6,请重新开始。否则,继续。

  5. 安装nodejs二进制文件。现在您的系统已经确认6.x可用,您可以安装它:sudo apt-get install nodejs

  6. nodejs --version现在应该在输出上显示v6.2.1或类似产品(只要它从v6.开始,你就是版本6;如果你使用的是比6更新的版本,这可能是更高的版本号,但只要它不是4.2 .6你应该好好去)。

次佳解决方案

我有一个旧版本的节点。我需要做的只是清除旧的:

sudo apt-get purge nodejs npm

然后,根据相应版本的需要,将v=6中的6替换为7,8,9(参见official installation instructions):

v=6
curl -sL https://deb.nodesource.com/setup_$v.x | sudo -E bash -

(确保你已经安装了卷发。)

最后,

sudo apt-get install -y nodejs

Boom,节点的最新版本。

第三种解决方案

对于Ubuntu 16.04.2版本的用户(从Thomas’post稍微改变并感谢他)

1.打开软件更新程序

2.设置

3.其他软件

4.添加源但记得选择以后的所有新源选项exp:


deb https://deb.nodesource.com/node_6.x xenial main
deb-src https://deb.nodesource.com/node_6.x xenial main

5.reload

6. sudo apt-get update

7. apt-cache policy nodejs //获取新版本表并检查源是否已完成设置

8. sudo apt install nodejs

9. nodejs --version

现在一切都设定…….

警告:不要从更新程序面板更改nvidia卡的Linux默认驱动程序….系统将崩溃…. !!!

第四种方案

我遇到过同样的问题。但在我的情况下,我不得不升级我的curl命令。您可以通过使用-S选项运行来查看该问题。

curl -s -S https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -

这显示了这个问题

curl: (1) Protocol "https" not supported or disabled in libcurl
gpg: no valid OpenPGP data found.

所以我通过运行以下内容解决了这个问题。

sudo apt-get install curl
sudo apt autoremove
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install nodejs

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/1344.html,未经允许,请勿转载。