
注意:這個問題已部分解決,但需要更多關注。請參閱 OP 底部的註釋和@Digisec 的部分答案。
我嘗試在 CentOS 7 上設定 Node.js,但以下命令無法安裝最新版本。 要在 CentOS 7 上安裝最新版本的 Node.js,我需要更改以下程式碼中的哪些內容?
我先輸入node --version
結果為v0.12.7
.這顯然是一個舊版本,因為nodejs.org
說這v5.6.0
是最新的穩定版本。
然後我輸入以下內容來取得最新版本的node.js:
cd /tmp
curl -sL https://rpm.nodesource.com/setup | bash -
終端列印我應該輸入以下內容來刪除過時的 Node.js 版本,因此我輸入以下內容:
yum remove -y nodejs npm
終端機還要求輸入以下內容來安裝最新版本的 Node.js,因此我輸入以下內容:
yum install -y nodejs
但隨後我node --version
再次輸入,終端v0.12.7
再次回覆 ,表明前面的命令只是再次重新安裝了舊的過時版本。
那我需要做什麼才能在 CentOS 7 機器上安裝最新穩定版本的 node.js 呢?
持續努力:
根據@Digisec的建議,我重新運行了上述命令,但這次將所有輸出記錄到以下文字。請注意,現在我再次運行它,順序略有不同,但結果是相同的,如下所示:
[root@localhost ~]# node --version
v0.12.7
[root@localhost ~]# cd /tmp
[root@localhost tmp]# curl -sL https://rpm.nodesource.com/setup | bash -
## Installing the NodeSource Node.js 0.10 repo...
## Inspecting system...
+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m
## Confirming "el7-x86_64" is supported...
+ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_0.10/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Downloading release setup RPM...
+ mktemp
+ curl -sL -o '/tmp/tmp.ePYEdVWXQH' 'https://rpm.nodesource.com/pub_0.10/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Installing release setup RPM...
+ rpm -i --nosignature --force '/tmp/tmp.ePYEdVWXQH'
## Cleaning up...
+ rm -f '/tmp/tmp.ePYEdVWXQH'
## Checking for existing installations...
+ rpm -qa 'node|npm' | grep -v nodesource
## Run `yum install -y nodejs` (as root) to install Node.js 0.10 and npm.
## You may also need development tools to build native addons:
## `yum install -y gcc-c++ make`
[root@localhost tmp]# yum remove -y nodejs npm
Loaded plugins: fastestmirror, langpacks
No Match for argument: npm
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be erased
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================================
Removing:
nodejs x86_64 0.10.42-1nodesource.el7.centos @nodesource 16 M
Transaction Summary
====================================================================================================================================================================================
Remove 1 Package
Installed size: 16 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : nodejs-0.10.42-1nodesource.el7.centos.x86_64 1/1
Verifying : nodejs-0.10.42-1nodesource.el7.centos.x86_64 1/1
Removed:
nodejs.x86_64 0:0.10.42-1nodesource.el7.centos
Complete!
[root@localhost tmp]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: www.gtlib.gatech.edu
* epel: mirror.sfo12.us.leaseweb.net
* extras: dallas.tx.mirror.xygenhosting.com
* updates: linux.mirrors.es.net
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================================
Installing:
nodejs x86_64 0.10.42-1nodesource.el7.centos nodesource 4.5 M
Transaction Summary
====================================================================================================================================================================================
Install 1 Package
Total download size: 4.5 M
Installed size: 16 M
Downloading packages:
nodejs-0.10.42-1nodesource.el7.centos.x86_64.rpm | 4.5 MB 00:00:09
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : nodejs-0.10.42-1nodesource.el7.centos.x86_64 1/1
Verifying : nodejs-0.10.42-1nodesource.el7.centos.x86_64 1/1
Installed:
nodejs.x86_64 0:0.10.42-1nodesource.el7.centos
Complete!
[root@localhost tmp]# node --version
v0.12.7
[root@localhost tmp]#
然後,根據 @Digisec 的回答,我接下來嘗試了以下方法,但結果還是沒能安裝正確的版本,從以下終端輸出可以看到:
[root@localhost tmp]# curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -
## Installing the NodeSource Node.js 5.x repo...
## Inspecting system...
+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m
## Confirming "el7-x86_64" is supported...
+ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Downloading release setup RPM...
+ mktemp
+ curl -sL -o '/tmp/tmp.NEM1bxM9WB' 'https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'
## Installing release setup RPM...
+ rpm -i --nosignature --force '/tmp/tmp.NEM1bxM9WB'
## Cleaning up...
+ rm -f '/tmp/tmp.NEM1bxM9WB'
## Checking for existing installations...
+ rpm -qa 'node|npm' | grep -v nodesource
## Run `yum install -y nodejs` (as root) to install Node.js 5.x and npm.
## You may also need development tools to build native addons:
## `yum install -y gcc-c++ make`
[root@localhost tmp]# yum remove -y nodejs npm
Loaded plugins: fastestmirror, langpacks
No Match for argument: npm
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be erased
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================================
Removing:
nodejs x86_64 0.10.42-1nodesource.el7.centos @nodesource 16 M
Transaction Summary
====================================================================================================================================================================================
Remove 1 Package
Installed size: 16 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : nodejs-0.10.42-1nodesource.el7.centos.x86_64 1/1
Verifying : nodejs-0.10.42-1nodesource.el7.centos.x86_64 1/1
Removed:
nodejs.x86_64 0:0.10.42-1nodesource.el7.centos
Complete!
[root@localhost tmp]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: www.gtlib.gatech.edu
* epel: mirror.sfo12.us.leaseweb.net
* extras: dallas.tx.mirror.xygenhosting.com
* updates: linux.mirrors.es.net
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================================
Installing:
nodejs x86_64 0.10.42-1nodesource.el7.centos nodesource 4.5 M
Transaction Summary
====================================================================================================================================================================================
Install 1 Package
Total download size: 4.5 M
Installed size: 16 M
Downloading packages:
nodejs-0.10.42-1nodesource.el7 FAILED
https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodejs-0.10.42-1nodesource.el7.centos.x86_64.rpm: [Errno 14] HTTPS Error 404 - Not Found ] 0.0 B/s | 0 B --:--:-- ETA
Trying other mirror.
To address this issue please refer to the below knowledge base article
https://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/
Error downloading packages:
nodejs-0.10.42-1nodesource.el7.centos.x86_64: [Errno 256] No more mirrors to try.
[root@localhost tmp]# yum install -y nodejs
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: www.gtlib.gatech.edu
* epel: mirror.sfo12.us.leaseweb.net
* extras: dallas.tx.mirror.xygenhosting.com
* updates: linux.mirrors.es.net
Resolving Dependencies
--> Running transaction check
---> Package nodejs.x86_64 0:0.10.42-1nodesource.el7.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================================
Installing:
nodejs x86_64 0.10.42-1nodesource.el7.centos nodesource 4.5 M
Transaction Summary
====================================================================================================================================================================================
Install 1 Package
Total download size: 4.5 M
Installed size: 16 M
Downloading packages:
No Presto metadata available for nodesource
nodejs-0.10.42-1nodesource.el7 FAILED
https://rpm.nodesource.com/pub_5.x/el/7/x86_64/nodejs-0.10.42-1nodesource.el7.centos.x86_64.rpm: [Errno 14] HTTPS Error 404 - Not Found ] 0.0 B/s | 0 B --:--:-- ETA
Trying other mirror.
To address this issue please refer to the below knowledge base article
https://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/
Error downloading packages:
nodejs-0.10.42-1nodesource.el7.centos.x86_64: [Errno 256] No more mirrors to try.
[root@localhost tmp]# node --version
v0.12.7
[root@localhost tmp]#
然後我訪問了上面錯誤日誌引用的知識庫文章,但發現我無法訪問完整的文章,因為我不是 Red Had 客戶。
部分解決方案:
@Digisec 透過展示如何安裝新版本部分解決了這個問題,但我們仍然無法刪除舊版本,這將留下未來發生衝突的風險。 需要採取哪些步驟來刪除舊版本,以便新安裝乾淨完整?
我發現舊版本 v0.12.7 的 tar url 在此鏈接。 @Digisec' 也建議閱讀這個另一個鏈接,建議使用命令make uninstall
。 我感覺可能只有五到十個命令可以在終端機中輸入來刪除舊的 v0.12.7 並重新安裝新版本的 nodejs。需要哪些指令?
我似乎使用以下終端命令在CentOS 7機器上找到了三個與nodejs v0.12.7相關的tar檔案:
[root@localhost ~]# cd /
[root@localhost /]# find . -type f -iname "*.tar"
find: ‘./run/user/1000/gvfs’: Permission denied
./opt/node-v0.12.7/deps/npm/node_modules/tar/test/dir-normalization.tar
./opt/node-v0.12.7/deps/npm/test/fixtures/gitignore-and-npmignore-2.tar
./opt/node-v0.12.7/deps/npm/test/fixtures/gitignore-and-npmignore.tar
./usr/local/lib/node_modules/npm/test/fixtures/gitignore-and-npmignore-2.tar
./usr/local/lib/node_modules/npm/test/fixtures/gitignore-and-npmignore.tar
./usr/local/lib/node_modules/npm/node_modules/tar/test/dir-normalization.tar
[root@localhost /]#
請注意,還有另外三個 tar 檔案被標記,node_modules
它們之間的關係v0.12.7
尚不清楚。
我需要運行哪些特定命令才能安全地從電腦中卸載v0.12.7
並刪除所有關聯的 tar 檔案?v0.12.7
答案1
我剛剛檢查了關聯你從那裡得到這個。具體來說,您正在安裝 version 0.10
,或至少正在嘗試安裝,但正在安裝的儲存庫中有一個較新的版本。您必須遵循節點 v5 的設定。
curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -
聚苯乙烯:為了將來的參考,請確保您非常仔細地閱讀這些站點,尤其是在運行命令時根。
編輯: 好吧,看來你添加了回購協議正確。查看儲存庫,您的軟體包在那裡,但係統正在尋找錯誤的版本。在這一點上,我建議。
yum clean all && yum update
這將清理快取的儲存庫並從遠端取得。
答:
在我們完成工作之後chat
,這是給您的正確答案。nodejs v5
安裝得很好。您之前是nodejs v0.12
手動編譯的,這對於二進制發行版來說不是一個好主意,因為您最終會處於這個位置。
which node
回
/usr/local/bin/node
儘管
/usr/bin/node
回了 的正確答案v5.x
。
此時您有多種選擇來修復它,但我建議使用 2。
- 選項1: 這是最簡單的方法。您可以編輯
.bashrc
並新增一個alias
將指向的node -> /usr/bin/node
。這就像添加一樣簡單alias node="/usr/bin/node"
。這每次都會調用正確的版本,但我不能保證它將來不會與庫發生衝突。 - 選項2: 雖然這個方法比較麻煩,但是還是可以解決的。首先,使用
yum
系統上安裝的nodejs進行清除。其次,取得已編譯版本的 tarball,解壓縮./configure
並卸載它。這一步,你可以發現在線的容易地。最後,nodejs
透過重新安裝yum
,這應該可以解決您的問題。
答案2
我做了什麼:
rm -f /etc/yum.repos.d/nodesource-el* 捲曲-sL https://rpm.nodesource.com/setup_7.x |重擊- yum安裝-ynodejs 節點--版本
我得到了:
v7.2.0
答案3
CentOS 7.2、NodeJS 6.7.0(https://nodejs.org/download/release/v6.7.0/)。手動安裝
wget https://nodejs.org/download/release/v6.7.0/node-v6.7.0.tar.gz
./configure
make
make install
解除安裝make uninstall
答案4
這裡同樣的問題。我為解決這個問題所做的事情是:
所有命令都必須以 root 身分執行,或至少在每個命令的開頭新增 SUDO
卸載nodejs - 在我的例子中是node v8
yum uninstall nodejs npm
從 /etc/yum.repos.d 中刪除實際儲存庫
rm /etc/yum.repos.d/nodesource*
更新您的儲存庫
yum update
取得更新的儲存庫 - 在我的範例中為 Node v14
curl -sL https://rpm.nodesource.com/setup_14.x | bash -
我喜歡進行新的 yum 更新(這是可選的)
yum update
安裝新版本的節點
yum install nodejs
享受
no code available for this