我尝试在 Linux 中安装/升级 Node.JS 出了什么问题?

我尝试在 Linux 中安装/升级 Node.JS 出了什么问题?

操作系统:Linux Mint 18.3。与Ubuntu类似。

与 Linux 一样,我真的不知道如何安装软件:

  1. 它已经在系统上了吗?在本例中是的,但它很旧:4.2.6。在撰写本文时,当前的 LTS 版本是 10.16.3。
  2. 我应该使用apt吗?
  3. 我应该使用软件管理器吗?
  4. 我应该使用 PPA 吗?
  5. 我应该下载压缩文件并解压吗?

其他用户的软件管理器评论是“到这里获取最新版本”(https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions

第一个命令是

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

这失败了:

> 
mike@M17A ~ $  curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
[sudo] password for mike: 

## Installing the NodeSource Node.js 10.x repo...


## Populating apt-get cache...

+ apt-get update
Ign:1 http://dl.google.com/linux/chrome/deb stable InRelease
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease                        
Hit:3 http://dl.google.com/linux/chrome/deb stable Release                     
Hit:4 http://ppa.launchpad.net/adabbas/1stppa/ubuntu xenial InRelease          
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]       
Get:6 http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]     

... // then many messages like this:

Ign:42 https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena/main all Packages
Ign:43 https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena/main Translation-en_GB
Ign:44 https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena/main Translation-en_GB
Ign:44 https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena/main Translation-en
Fetched 329 kB in 23s (14.0 kB/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://repository.spotify.com stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4773BD5E130D1D45
W: The repository 'https://mirrors.evowise.com/mariadb/repo/10.1/ubuntu serena Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: The repository 'https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: Failed to fetch http://repository.spotify.com/dists/stable/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4773BD5E130D1D45
E: Failed to fetch https://mirrors.evowise.com/mariadb/repo/10.1/ubuntu/dists/serena/main/binary-amd64/Packages  404  Not Found
E: Failed to fetch https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu/dists/serena/main/binary-amd64/Packages  404  Not Found
W: Some index files failed to download. They have been ignored, or old ones used instead.
Error executing command, exiting

...我不确定所有这些 mariadb 命令都是关于什么的。我的系统上有 MariaDB,我担心出现问题。

注意尝试下一个命令似乎表明这已经失败:

mike@M17A ~ $  sudo apt-get install -y nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
nodejs is already the newest version (4.2.6~dfsg-1ubuntu4.2).
0 to upgrade, 0 to newly install, 0 to remove and 600 not to upgrade.

...即系统仍然认为4.2.6是最新版本。

更一般地说,在 Linux 中安装新软件的协议到底是什么:上面的编号列表(1 到 5)是正确的方法吗?专家安装新软件时采用什么优先级顺序?

我随后尝试

看来失败sudo apt-get update才是问题的根源。

受到其他问题的启发,我尝试了这个:

sudo rm /var/lib/apt/lists/* -vf

接下来是:

sudo apt-get update

更多错误和警告列表对我来说意义不大:

...
Err:40 https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena/main amd64 Packages
  404  Not Found
Ign:41 https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena/main i386 Packages
Ign:42 https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena/main all Packages
Ign:43 https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena/main Translation-en_GB
Ign:44 https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena/main Translation-en
Fetched 329 kB in 28s (11.6 kB/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://repository.spotify.com stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4773BD5E130D1D45
W: The repository 'https://mirrors.evowise.com/mariadb/repo/10.1/ubuntu serena Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: The repository 'https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: Failed to fetch http://repository.spotify.com/dists/stable/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4773BD5E130D1D45
E: Failed to fetch https://mirrors.evowise.com/mariadb/repo/10.1/ubuntu/dists/serena/main/binary-amd64/Packages  404  Not Found
E: Failed to fetch https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu/dists/serena/main/binary-amd64/Packages  404  Not Found
W: Some index files failed to download. They have been ignored, or old ones used instead.

后来我在github页面尝试了“手动安装”...... 以同样的方式失败:

mike@M17A ~ $  VERSION=node_10.16.3
mike@M17A ~ $  DISTRO="$(lsb_release -s -c)"
mike@M17A ~ $  echo "deb https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_10.16.3 sylvia main
mike@M17A ~ $  echo "deb-src https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
deb-src https://deb.nodesource.com/node_10.16.3 sylvia main
mike@M17A ~ $  sudo apt-get update
Hit:1 http://ppa.launchpad.net/adabbas/1stppa/ubuntu xenial InRelease
...

Ign:57 https://deb.opera.com/opera-stable stable/non-free Translation-en
Err:58 https://deb.opera.com/opera-stable stable/non-free amd64 Packages
  503  Backend unavailable, connection timeout
Ign:59 https://deb.opera.com/opera-stable stable/non-free i386 Packages
Fetched 3,316 B in 34s (95 B/s)
Reading package lists... Done
W: The repository 'https://deb.nodesource.com/node_10.x sylvia Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: GPG error: http://repository.spotify.com stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4773BD5E130D1D45
W: The repository 'http://repository.spotify.com stable InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: The repository 'https://mirrors.evowise.com/mariadb/repo/10.1/ubuntu serena Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: The repository 'https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu serena Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: The repository 'https://deb.opera.com/opera-stable stable Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch https://deb.nodesource.com/node_10.x/dists/sylvia/main/binary-amd64/Packages  404  Not Found
E: Failed to fetch https://mirrors.evowise.com/mariadb/repo/10.1/ubuntu/dists/serena/main/binary-amd64/Packages  404  Not Found
E: Failed to fetch https://mirrors.evowise.com/mariadb/repo/10.2/ubuntu/dists/serena/main/binary-amd64/Packages  404  Not Found
E: Failed to fetch https://deb.opera.com/opera-stable/dists/stable/non-free/binary-amd64/Packages  503  Backend unavailable, connection timeout
E: Some index files failed to download. They have been ignored, or old ones used instead.

答案1

当您安装时,node.jssudo apt install nodejs将获得一个版本,该版本经过测试在您的 Linux 发行版中稳定。这也意味着您将获得该软件的相当过时的版本,并且某些软件包将拒绝使用它。例如,当前版本的Rocket.Chatrequire node.js >= 12,而在我的Ubuntu 20.04官方版本是类似 10.x 的东西。在您编写问题时,它可能是相当新的,这就是您使用命令的原因

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

执行一个脚本,安装版本node.js-10.x

据我所知,脚本抱怨的问题是它无法找到它正在使用的某些存储库的公钥。密钥的问题常常是由于root用户的一些奇怪的设置,导致密钥文件的权限错误。

解决办法是检查目录权限

$ ls -l /etc/apt/sources.list.d/
$ ls -l /usr/share/keyrings/

它们应该看起来像这样(-rw-r--r--是许可644

-rw-r--r-- 1 root root  2206 Aug 25 00:40 nodesource.gpg

如果某些文件的输出不同,请手动更改

sudo chmod 644 /usr/share/keyrings/nodesource.gpg

答案2

我成功了。最后我发现我必须调整安装脚本。

具体来说,这是来自这里。然而,我没有执行 CURL 命令,而是从该 URL 下载了脚本,并用“apt-get update”注释掉了这两行……然后命名该文件并使其可执行并运行它。

然后我就去了

sudo apt-get update

然后我就去了

sudo apt-get install nodejs

原因是apt-get update当前在我的系统上返回错误,并且它出现这会在脚本在源列表中设置 PPA 之前终止脚本(这是正确的术语吗?)。我对此可能是错的。我是一个Linux底层人。

注意,脚本似乎是必要的,尤其是我注意到有一个部分,文件将从我的系统中找到的“Linux Mint”-“sylvia”“翻译”为“Ubuntu”-“xenial”。事实上,在下载站点上,URL“.../Linux Mint/sylvia/...”不存在,并且返回 404。

相关内容