Centos上yum安装nodejs

Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器(源镜像地址)自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

直接使用yum install nodejs可能会遇到如下情况:源镜像mirrors.aliyun.com上没有nodejs安装包。

[root@localhost yum.repos.d]# yum install -y nodejs
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No package nodejs available.
Error: Nothing to do
  1. 确认Centos版本:uname -r
  2. 添加epel源:epel (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适用于RHEL、CentOS和Scientific Linux.

    1)x86_64:rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    2)i386:rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

  3. 导入epel源的key:rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
  4. 添加 remi 源:rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
  5. 导入remi源的key:rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-remi
  6. 下载并安装
    curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
    yum -y install nodejs
    [root@localhost yum.repos.d]# yum install -y nodejs
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Setting up Install Process
    Loading mirror speeds from cached hostfile
    epel/metalink                                            | 6.1 kB     00:00     
     * base: mirrors.aliyun.com
     * epel: ftp.jaist.ac.jp
     * extras: mirrors.aliyun.com
     * remi-safe: mirrors.tuna.tsinghua.edu.cn
     * updates: mirrors.aliyun.com
    

    可以看到yum安装nodejs时,源镜像添加了epel和remi-safe,从而可以下载到nodejs的安装包,并成功安装。

  7. 检查Node.js和npm版本:
    node -v
    npm -v 
     

 


版权声明:本文为ice_ly000原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。