我嘗試在 Linux 中安裝/升級 Node.JS 出了什麼問題?
作業系統:Linux Mint 18.3。類似於 Ubuntu。
與 Linux 一樣,我真的不知道我打算如何安裝軟體:
- 它已經在系統上了嗎?在這種情況下是的,但它很舊:4.2.6。在撰寫本文時,目前的 LTS 版本是 10.16.3。
- 我應該使用apt嗎?
- 我應該使用軟體管理器嗎?
- 我應該使用 PPA 嗎?
- 我應該下載壓縮文件並解壓縮嗎?
來自其他使用者的軟體管理器評論類似於“去這裡獲取最新版本”(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,我擔心有什麼問題。
NB 嘗試下一個命令似乎表明這已經失敗:
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.
我做到了。最後我發現我不得不調整一個安裝腳本。
具體來說這是從這裡來的。但是,我沒有執行 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。
當您
node.js
使用安裝時,sudo apt install nodejs
您將獲得一個版本,該版本經過測試在您的 Linux 發行版中是穩定的。這也意味著您會得到一個非常過時的軟體版本,並且某些軟體包會拒絕使用它。例如目前版本的Rocket.Chat
requiresnode.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