Ubuntu 16.04实际安装了node 4.2.6,为什么不安装 node 6.x?

分享于 

6分钟阅读

ubuntu

  繁體

问题

以下是我在Ubuntu 16.04上安装node的步骤:


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

我如何在Ubuntu 16.04上安装最新的稳定版node?

这些是运行后的结果 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




答案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_6.x替换为node_7.xnode_8.x,更新版本

  • 从Nodesource下载仓库的GPG签名密钥,否则,你得到NO_PUBKEY错误,apt-get update

    
    curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
    
    
    
    
  • 手动运行sudo apt-get update

    如果出现NO_PUBKEY GPG错误,请返回步骤2

  • 检查apt-cache policy nodejs输出。

    
    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,则重新开始,否则,继续。

  • 安装nodejs二进制文件,确认6.x在系统上可用后,就可以安装它: sudo apt-get install nodejs

  • nodejs --version现在应该在输出中显示v6.2.1或类似的。


  • 答案2

    我有一个旧版本的node,

    
    sudo apt-get purge nodejs npm
    
    
    
    

    然后,根据需要将v=6中的6替换为7.8:

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

    请确保已安装curl。

    最后,

    
    sudo apt-get install -y nodejs
    
    
    
    


    相关文章