ทำไม Node.js เวอร์ชั่นใหม่ที่ถูกต้องจะไม่ติดตั้งบน CentOS 7


12

หมายเหตุ: ส่วนนี้ได้รับการแก้ไขแล้ว แต่ต้องการความสนใจเพิ่มขึ้นเล็กน้อย ดูโน้ตที่ด้านล่างของ OP และคำตอบบางส่วนของ @ Digisec

ฉันพยายามตั้งค่า Node.js บน CentOS 7 แต่คำสั่งต่อไปนี้ล้มเหลวในการติดตั้งเวอร์ชันล่าสุด ฉันต้องเปลี่ยนอะไรในรหัสด้านล่างเพื่อติดตั้ง Node.js เวอร์ชั่นใหม่ล่าสุดบน CentOS 7

ผมเริ่มต้นด้วยการพิมพ์ซึ่งส่งผลให้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อีกครั้งแสดงว่าคำสั่งก่อนหน้าเพียงแค่ติดตั้งเวอร์ชันเก่าที่ล้าสมัยอีกครั้ง

ดังนั้นฉันต้องทำอย่างไรจึงจะสามารถติดตั้ง node.js เวอร์ชันเสถียรล่าสุดบนเครื่อง CentOS 7 ได้?


ความพยายามอย่างต่อเนื่อง:


ตามคำแนะนำของ @ 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 แก้ไขบางส่วนโดยแสดงวิธีการติดตั้งเวอร์ชันใหม่ แต่เรายังไม่สามารถลบเวอร์ชันเก่าออกได้ซึ่งจะทำให้เกิดความเสี่ยงต่อความขัดแย้งในอนาคต ขั้นตอนใดที่ต้องดำเนินการเพื่อลบเวอร์ชันเก่าออกเพื่อให้การติดตั้งใหม่นั้นสะอาดและสมบูรณ์

ฉันพบtar URL สำหรับเวอร์ชั่นเก่า v0.12.7 ที่ลิงก์นี้ และ @Digisec' ยังแนะให้อ่านนี้การเชื่อมโยงอื่น ๆ make uninstallซึ่งแนะนำให้ใช้คำสั่ง ฉันเข้าใจว่าอาจมีเพียงห้าหรือสิบคำสั่งในการพิมพ์เทอร์มินัลเพื่อลบ v0.12.7 เก่าและติดตั้ง nodejs เวอร์ชันใหม่อีกครั้ง คำสั่งที่จำเป็นคืออะไร?

ฉันดูเหมือนจะพบไฟล์ tar สามไฟล์บนเครื่อง CentOS 7 ที่เกี่ยวข้องกับ nodejs v0.12.7 โดยใช้คำสั่งเทอร์มินัลต่อไปนี้:

[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และลบv0.12.7ไฟล์ tar ที่เกี่ยวข้องทั้งหมดออกจากเครื่อง


มันจะเป็นความคิดที่ดีที่จะโพสต์เอาท์พุททั้งหมดเช่นกัน นั่นจะช่วยให้เห็นว่ามีอะไรเกิดขึ้นเพื่อให้สามารถช่วยเหลือคุณได้ดียิ่งขึ้น
Digisec

@Digisec ฉันรันคำสั่งอีกครั้งแล้วเพิ่มเอาต์พุตที่สมบูรณ์ลงใน OP ตามที่คุณร้องขอ ฉันสามารถทำสิ่งอื่นเพื่อแยกปัญหาได้หรือไม่
CodeMed

FWIW ตอนนี้คุณอาจถอนการติดตั้งรุ่นเก่า NodeJS yum remove -y nodejsด้วย
avazula

คำตอบ:


7

ฉันเพิ่งตรวจสอบลิงก์ที่คุณได้รับจากนี้ คุณกำลังติดตั้งโดยเฉพาะรุ่น0.10หรือพยายามอย่างน้อยที่สุด แต่คุณมีเวอร์ชันที่ใหม่กว่าใน repo ที่กำลังติดตั้ง คุณต้องทำตามการตั้งค่าสำหรับโหนด v5

curl --silent --location https://rpm.nodesource.com/setup_5.x | bash -

PS : สำหรับการอ้างอิงในอนาคตให้แน่ใจว่าคุณอ่านเว็บไซต์อย่างระมัดระวังโดยเฉพาะอย่างยิ่งเมื่อใช้คำสั่งเป็นราก

แก้ไข: เอาล่ะดูเหมือนว่าคุณจะเพิ่มrepoอย่างถูกต้อง เมื่อมองเข้าไปที่ repo แพ็คเกจของคุณจะอยู่ที่นั่น แต่ระบบกำลังมองหาเวอร์ชั่นที่ผิด ณ จุดนี้ฉันอยากจะแนะนำ

yum clean all && yum update

ที่จะทำความสะอาด repo ที่เก็บไว้และคว้าจากระยะไกล

คำตอบ: หลังจากงานที่เราทำเสร็จchatแล้วนี่คือคำตอบที่ถูกต้องสำหรับคุณ nodejs v5ติดตั้งดี ก่อนหน้านี้คุณรวบรวมnodejs v0.12ด้วยตนเองซึ่งไม่ใช่ความคิดที่ดีสำหรับไบนารี distros เพราะคุณจะอยู่ในตำแหน่งนี้

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 : นี่เป็นวิธีที่ยาก แต่จะแก้ไขได้ ก่อนอื่นให้ล้างข้อมูลด้วยyumnodejs ที่ติดตั้งบนระบบ ประการที่สองรับ tarball สำหรับรุ่นที่คุณรวบรวมถอดออก./configureและถอนการติดตั้ง ขั้นตอนนี้คุณสามารถค้นหาออนไลน์ได้อย่างง่ายดาย สุดท้ายติดตั้งnodejsผ่านyumและที่ควรแก้ไขปัญหาของคุณ

ขอบคุณที่ตรวจสอบสิ่งนี้ แต่ยังไม่สามารถแก้ไขปัญหาได้อย่างเต็มที่ โปรดดูเทอร์มินัลเอาท์พุทเพิ่มเติมที่ฉันเพิ่มเข้าไปที่ส่วนท้ายของเอกสารประกอบ OP ผลลัพธ์ของการลองใช้ข้อเสนอแนะของคุณ ฉันจะลองทำอะไรอีก
CodeMed

@CodeMed ฉันอัปเดตคำตอบและมันจะเป็นความคิดที่ดีกว่าที่จะเข้าสู่การแชท
Digisec

นั่นไม่ได้แก้ปัญหา หากคุณยังคงเต็มใจที่จะแชทฉันได้สร้างห้องต่อไปนี้: chat.stackexchange.com/rooms/35670/…
CodeMed

@CodeMed โชคดีกับการแก้ไขปัญหาของคุณ
Digisec

คุณเต็มใจที่จะอธิบายอย่างละเอียดในตัวเลือกของคุณ 2 หรือไม่? หรือฉันควรโพสต์คำถามแยกต่างหาก
CodeMed

4

ฉันทำอะไรลงไป:

rm -f /etc/yum.repos.d/nodesource-el*
curl -sL https://rpm.nodesource.com/setup_7.x | ทุบตี -
yum install -y nodejs
โหนด - รุ่น

และฉันได้รับ:

v7.2.0

ขอบคุณ! นี่เป็นทางออกเดียวที่ช่วยฉัน
626

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


1

ฉันพยายามติดตั้งโหนดจากเดียวกันNodeSource RepoInstaller สำหรับวิธีการแก้ไขปัญหาของฉันโดยเปิดใช้nodesourcerepo เปลี่ยนenabled=0เป็นenabled=1และทั้งหมดควรใช้งานได้

[root@web ~]# cat /etc/yum.repos.d/nodesource-el.repo
[nodesource]
name=Node.js Packages for Enterprise Linux 7 - $basearch
baseurl=https://rpm.nodesource.com/pub_6.x/el/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL

0

ฉันยังมีปัญหาบางอย่างในการรับเวอร์ชันใหม่ของ npm และ nodejs ที่ติดตั้งบน CentOS 7

ฉันทำตามคำแนะนำบนเว็บไซต์ nodejs จากนั้นพยายามติดตั้ง npm สิ่งนี้กลายเป็นปัญหา (มีการติดตั้ง npm จาก EPEL) ที่เก็บ Nodesource ไม่ได้จัดเตรียมแพ็กเกจเดี่ยวสำหรับ npm ตามที่เป็นกรณีสำหรับ EPEL แต่ทุกอย่างอยู่ในแพ็คเกจเดียว 'nodejs' ดังนั้นเมื่อคุณติดตั้ง nodejs จาก Nodesource ตอนนี้คุณได้ติดตั้ง npm โดยอัตโนมัติและพร้อมที่จะดำเนินการกับเวอร์ชันที่อัปเดตแล้ว


0

ฉันกำลังดิ้นรนกับปัญหาเดียวกันหรือyum clean allไม่rm -f /etc/yum.repos.d/nodesource*ช่วย จากนั้นฉันก็พบว่า yum ใช้ที่เก็บ Epel เพื่อติดตั้งโหนดดังนั้นฉันจึงปิดการใช้งานชั่วคราว (ใน/etc/yum.repos.d/epel.repoชุดenabled=0) และหลังจากนั้น

curl -sL https://rpm.nodesource.com/setup_8.x | bash -
yum install nodejs

0

ฉันยังต้องเผชิญกับปัญหาเดียวกัน

โซลูชัน: 1. ไป/tmpที่ตำแหน่งลบไฟล์และโฟลเดอร์ทั้งหมด

cd /tmp
rm -rf *

2. ตอนนี้คุณสามารถใช้คำสั่งด้านล่างเพื่อติดตั้ง NodeJs

curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
sudo yum install -y nodejs
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.