今天在导出 Drupal 数据库时,碰到一个 phpMyAdmin 的Bug,我把 phpMyAdmin 升级了一下,发现 phpMyAdmin 在 EPEL 库中的最新版还不是 phpMyAdmin 官方发布的最新版(4.4版),在这个版本中 Bug 依然存在,那要怎么才能升级到官方的最新版呢?

我们可以给 CentOS 添加额外的仓库,也就是第三方的软件仓库,本文主要介绍EPEL、IUS、Remi这三个库的安装方法(本文中皆以64-bit包做介绍)。

需要注意的是,这个三个库是有区别的,其中 EPEL 只提供 CentOS 和 Red Hat Enterprise Linux 官方仓库中没有的软件,而 IUS 和 Remi 提供的软件是官方仓库中已经有的(比如 MySQL 和 PHP),但是版本要比官方仓库中的更新。

安装 EPEL

CentOS Extras repository

CentOS 附加库已经包括了一个可以安装 EPEL 的包,默认是启用的。要安装 EPEL 包,只需执行下面的命令:

sudo yum install epel-release

如果上面的命令不管用,可能是附加包没有启用,那么可以按照下面的命令来手动安装:

CentOS and Red Hat Enterprise Linux 5.x

wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
sudo rpm -Uvh epel-release-5*.rpm

CentOS and Red Hat Enterprise Linux 6.x

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh epel-release-6*.rpm

CentOS and Red Hat Enterprise Linux 7.x

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
sudo rpm -Uvh epel-release-7*.rpm

如果出现"File Not Found"错误,很有可能是安装包的版本号变了,可以参考 [Fedora EPEL wiki](https://fedoraproject.org/wiki/EPEL) 页面 ,确认一下版本号是否正确。

## 安装 IUS repository

### CentOS 5.x

~~~bash
wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/5/x86_64/ius-release-1.0-13.ius.centos5.noarch.rpm
sudo rpm -Uvh ius-release*.rpm

CentOS 6.x

wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/ius-release-1.0-13.ius.centos6.noarch.rpm
sudo rpm -Uvh ius-release*.rpm

CentOS 7.x

wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/ius-release-1.0-13.ius.centos7.noarch.rpm
sudo rpm -Uvh ius-release*.rpm

Red Hat 5.x

wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/5/x86_64/ius-release-1.0-13.ius.el5.noarch.rpm
sudo rpm -Uvh ius-release*.rpm

Red Hat 6.x

wget http://dl.iuscommunity.org/pub/ius/stable/RedHat/6/x86_64/ius-release-1.0-13.ius.el6.noarch.rpm
sudo rpm -Uvh ius-release*.rpm

Red Hat 7.x

wget http://dl.iuscommunity.org/pub/ius/stable/RedHat/7/x86_64/ius-release-1.0-13.ius.el7.noarch.rpm
sudo rpm -Uvh ius-release*.rpm

如果出现"File Not Found"错误,很有可能是 RPM 的版本号变了,最新版本可以参考 IUS Release Packages Page

把已经安装的软件包升级到 IUS 版

如果已经安装过某个软件包了,现在想把它升级到 IUS 仓库中的新版,可以安装软件包替换插件 IUS yum plug-in 来简化升级过程:

sudo yum install yum-plugin-replace

这个插件提供了一个 yum 替换命令,可以同时替换某个特定的软件包以及它的依赖包。比如用 IUS 仓库中的 PHP 5.3 来替换已经安装的 PHP,可以运行下面的命令:

sudo yum replace php --replace-with php53

更详细的介绍,可以参考 IUS Client Usage Guide

安装 Remi repository

CentOS and Red Hat Enterprise Linux 5.x

wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
sudo rpm -Uvh remi-release-5*.rpm

CentOS and Red Hat Enterprise Linux 6.x

wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6*.rpm

CentOS and Red Hat Enterprise Linux 7.x

wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
sudo rpm -Uvh remi-release-7*.rpm

如果出现"File Not Found"错误,很有可能是 RPM 的版本号变了,最新版本可以到 Remi RPM Repository 查看。

启用 Remi repository

Remi repository 默认是禁用的(因为包名称和官方的一样,可能会产生一些不必要的麻烦)。

请确保只有真正需要时再启用,在安装软件包时使用 --enablerepo=remi 来启用Remi 仓库:

sudo yum --enablerepo=remi install php-tcpdf

如果想永久启用 Remi repository,需要修改 yum 配置文件:

sudo nano /etc/yum.repos.d/remi.repo
Edit the [remi] portion of the file to set the enabled option to 1. This action enables the Remi repository by default.
name=Les RPM de remi pour Enterprise Linux $releasever - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/$releasever/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/$releasever/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
failovermethod=priority

检查可以使用的库

可以通过下面的命令来查看自己需要的库是否已经安装:

yum repolist

有些库默认是禁用的,比如 Remi,要查看已经禁用的仓库,可以用下面的命令:

yum repolist disabled

额外的注意事项

因为Remi库中包的名字和官方库中的是一样的,所以,如果你的服务器或者云服务是默认每天自动更新的话,很可能会产生软件版本的冲突,或者是并不想升级但是无意中 yum update 把某些软件升级了。

(本文参考文章: Install EPEL and additional repositories on CentOS and Red Hat