以下是详细讲解 CentOS 离线安装gcc(版本4.8.2)的完整攻略:
需要下载的软件包
在进行离线安装 GCC 时,我们需要下载以下软件包:
- GCC 4.8.2 源码包:可以在 ftp://ftp.gnu.org/pub/gnu/gcc/ 下载,选择 gcc-4.8.2.tar.gz 下载。
- GMP、MPFR、MPC 库:这三个库是 GCC 构建过程中所需的依赖库。可以在以下网址下载:
- GMP库:https://gmplib.org/download/gmp/,选择 gmp-5.0.5.tar.bz2 下载;
- MPFR库:http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.bz2;
- MPC库:ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.tar.gz。
安装过程
1.将上述下载的三个依赖库解压,并分别进入各自的解压目录中,执行以下命令进行编译及安装:
./configure --prefix=/usr/local/gmp
make
sudo make install
./configure --prefix=/usr/local/mpfr --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib
make
sudo make install
./configure --prefix=/usr/local/mpc --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib
make
sudo make install
2.将下载的 GCC 源码包解压,进入解压目录中,执行以下命令进行编译及安装(此处以安装在 /usr/local/gcc 下为例):
./configure --prefix=/usr/local/gcc --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib --with-mpc-include=/usr/local/mpc/include --with-mpc-lib=/usr/local/mpc/lib
make
sudo make install
3.在 /etc/profile 中添加如下配置:
export PATH=$PATH:/usr/local/gcc/bin
4.执行 source /etc/profile 生效。
经过上述步骤,GCC 4.8.2 就已经成功安装在指定的目录下了。
示例说明
示例一
假设我们已经将 GCC 4.8.2 及其依赖库的安装包下载到 /opt 目录下,我们可以将其解压到 /tmp 目录中,并安装到 /usr/local 目录下:
1.执行以下命令解压 GCC 和依赖库安装包:
cd /opt
tar -xzvf gcc-4.8.2.tar.gz
tar -xjf gmp-5.0.5.tar.bz2
tar -xjf mpfr-2.4.2.tar.bz2
tar -xzvf mpc-1.0.tar.gz
2.分别进入各自的解压目录中,执行以下命令进行编译及安装:
cd /tmp/gmp-5.0.5
./configure --prefix=/usr/local/gmp
make
sudo make install
cd /tmp/mpfr-2.4.2
./configure --prefix=/usr/local/mpfr --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib
make
sudo make install
cd /tmp/mpc-1.0
./configure --prefix=/usr/local/mpc --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib
make
sudo make install
3.将 GCC 解压目录进入 /tmp 目录下,执行以下命令编译及安装:
cd /tmp/gcc-4.8.2
./configure --prefix=/usr/local/gcc --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib --with-mpc-include=/usr/local/mpc/include --with-mpc-lib=/usr/local/mpc/lib
make
sudo make install
示例二
假设我们已经将 GCC 4.8.2 及其依赖库的安装包上传到了一台离线服务器的 /opt 目录下,我们需要在该服务器上进行安装:
- 将 /opt 目录下的安装包拷贝至对应的目录下:
scp /opt/gmp-5.0.5.tar.bz2 username@your_server_ip:/tmp/
scp /opt/mpfr-2.4.2.tar.bz2 username@your_server_ip:/tmp/
scp /opt/mpc-1.0.tar.gz username@your_server_ip:/tmp/
scp /opt/gcc-4.8.2.tar.gz username@your_server_ip:/tmp/
- 使用 SSH 登录至服务器,并进行解压及安装:
ssh username@your_server_ip
cd /tmp
tar -xjf gmp-5.0.5.tar.bz2
tar -xjf mpfr-2.4.2.tar.bz2
tar -xzvf mpc-1.0.tar.gz
tar -xzvf gcc-4.8.2.tar.gz
cd gmp-5.0.5/
./configure --prefix=/usr/local/gmp
make
sudo make install
cd /tmp/mpfr-2.4.2
./configure --prefix=/usr/local/mpfr --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib
make
sudo make install
cd /tmp/mpc-1.0
./configure --prefix=/usr/local/mpc --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib
make
sudo make install
cd /tmp/gcc-4.8.2
./configure --prefix=/usr/local/gcc --with-gmp-include=/usr/local/gmp/include --with-gmp-lib=/usr/local/gmp/lib --with-mpfr-include=/usr/local/mpfr/include --with-mpfr-lib=/usr/local/mpfr/lib --with-mpc-include=/usr/local/mpc/include --with-mpc-lib=/usr/local/mpc/lib
make
sudo make install
完成以上操作后,GCC 4.8.2 就成功安装在离线服务器上了。
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:CentOS 离线安装gcc(版本4.8.2)详细介绍 - Python技术站