yum 源里最新的 gcc 版本是 4.8.5,但很多时候安装软件依赖于更高版本的 gcc,这时候只能通过手动源码安装最新版。

使用源码编译安装gcc耗时非常大,请要有耐心等待,耐心等待,耐心等待,重要的事情说三遍。

如果你觉得步麻烦可以使用 gcc一键安装 帮你完成!

1、下载并解压源码

wget https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz
tar -zxf gcc-9.2.0.tar.gz
cd gcc-9.2.0

备用下载地址:https://down.24kplus.com/linux/gcc-9.2.0.tar.gz

2、编译安装

下载必要软件包

./contrib/download_prerequisites

如果提示 tar (child): lbzip2: Cannot exec: No such file or directory 错误:

yum -y install bzip2

编译安装gcc

./configure --prefix=/usr \
--mandir=/usr/share/man \
--infodir=/usr/share/info \
--enable-bootstrap \
--enable-shared \
--enable-threads=posix \
--enable-checking=release \
--with-system-zlib \
--enable-__cxa_atexit \
--disable-libunwind-exceptions \
--enable-gnu-unique-object \
--enable-linker-build-id \
--with-linker-hash-style=gnu \
--enable-languages=c,c++ \
--enable-plugin \
--enable-initfini-array \
--disable-libgcj \
--enable-gnu-indirect-function \
--with-tune=generic \
--with-arch_32=x86-64 \
--build=x86_64-redhat-linux \
--disable-multilib
make
make install

如果出现 configure: error: GNAT is required to build ada 错误

yum -y install gcc-gnat -y

如果出现 fatal error: zlib.h: No such file or directory 错误

yum install zlib-devel -y

如果出现 configure: error: C++ preprocessor "/lib/cpp" fails sanity check 错误

yum install gcc-c++ -y

如果出现 makeinfo: command not found 错误

yum install texinfo -y

为了避免日后编译软件发生 checking for C compiler … not found 错误,执行:

ln -s /usr/bin/gcc /usr/bin/cc

4、检查是否正确安装

gcc -v

CentOS 7 源码安装 libzip 1.5.2,解决 error: Please reinstall the libzip distributioerror: system libzip must be upgraded to version >= 0.11 错误。

1、准备编译环境

yum install openssl-devel bzip2 bzip2-devel

2、下载源码,并解压

wget https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxf libzip-1.5.2.tar.gz
cd libzip-1.5.2

备用下载地址:https://down.24kplus.com/linux/libzip-1.5.2.tar.gz

3、编译安装

mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=/usr .. && make
sudo make install

如果提示 cmake: command not found,需要先安装 cmake

CentOS 7 源码安装 CMake 3.15.5 最新稳定版。解决 cmake: command not found 问题。

1、准备编译环境

yum -y install gcc gcc-c++

2、获取源码,并解压

wget https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5.tar.gz
tar -zxf cmake-3.15.5.tar.gz
cd cmake-3.15.5

备用下载地址:https://down.24kplus.com/linux/cmake/cmake-3.15.5.tar.gz

3、编译安装

./bootstrap --prefix=/usr --datadir=share/cmake --docdir=doc/cmake && make
sudo make install

4、检查是否正确安装

cmake --version

cmake version 3.15.5

CMake suite maintained and supported by Kitware (kitware.com/cmake).

CentOS 7 通过源码安装 re2c 最新版,解决 configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers 问题。

1、准备编译环境

yum -y install git automake gcc+ gcc-c++ libtool

2、获取源码、并编译安装

git clone https://github.com/skvadrik/re2c.git re2c
cd re2c
mkdir -p m4
./autogen.sh && ./configure --prefix=/usr && make
sudo make install

备用下载地址: https://down.24kplus.com/linux/re2c-1.1.1.tar.gz

3、检查是否安装成功

re2c -v

re2c 1.1.1

官方安装文档:http://re2c.org/install/install.html

MySQL

1、安装 MySQL 源

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

2、选择想要安装的版本

使用MySQL Yum repository 时,默认选择安装MySQL的最新GA版本。 如果是你想要安装的,你可以跳到下一步,用 Yum 安装 MySQL。

yum repolist all | grep mysql

如果安装最新的GA版本,不需要进行任何配置。 要从最新GA版本以外的特定版本 安装最新版本,请在运行安装命令之前禁用最新GA版本的子 repository 并启用特定版本的子 repository。执行以下命令来执行此操作,这些命令禁用8.0版本的子 repository 并启用5.7版本的子 repository:

sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community

运行以下命令并检查其输出来验证是否已启用和禁用了正确的子 repository

yum repolist enabled | grep mysql

3、开始安装 MySQL

sudo yum install mysql-community-server

4、启动 MySQL 服务

sudo systemctl start mysqld.service

检查 MySQL 是否正确启动:

sudo systemctl status mysqld.service

5、修改登录密码

通过以下命令查看默认的临时密码:

sudo grep 'temporary password' /var/log/mysqld.log

登录 MySQL

mysql -u root -p

修改密码,并使密码生效 (注意 NewPassword 替换为你想要设置的登录密码) :

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
FLUSH PRIVILEGES;

6、开启 root 用户远程访问(可选)

执行以下命令(注意 Password 替换为你想要设置的登录密码):

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Password' WITH GRANT OPTION;
FLUSH PRIVILEGES;

官方英文安装文档:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

Docker

Docker是一个开放源代码软件项目,让应用程序部署在软件货柜下的工作可以自动化进行,借此在Linux操作系统上,提供一个额外的软件抽象层,以及操作系统层虚拟化的自动管理机制。

1、卸载旧版 Docker

老版本的 Docker 被称为 dockerdocker-engine 。如果安装了,需要先卸载它们以及相关的依赖项。

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

2、添加 Docker CE 源

wget https://download.docker.com/linux/centos/docker-ce.repo
sudo mv docker-ce.repo /etc/yum.repos.d/docker-ce.repo

3、安装 Docker CE 和 Containered 最新版

sudo yum install docker-ce docker-ce-cli containerd.io

4、启动 Docker CE 服务

sudo systemctl start docker

查看 Docker CE 版本

docker -v

Docker version 18.09.6, build 481bc77156

官方英文安装: https://docs.docker.com/install/linux/docker-ce/centos/

Welcome to nginx!

安装

1、准备编译环境

yum -y install libxml2 libxml2-devel libxslt-devel gd-devel gperftools libuuid-devel libblkid-devel libudev-devel fuse-devel libedit-devel libatomic_ops-devel gcc-c++

以及安装 libmaxminddb(如不启用 GeoIP2 模块可以忽略)

2、下载并解压

由于 GeoIP 官方已不再支持,如果要支持最新 GeoIP2 ,需要添加ngx_http_geoip2_module。下载 GeoIP2 模块

git clone https://github.com/leev/ngx_http_geoip2_module.git

下载,解压

wget https://nginx.org/download/nginx-1.16.0.tar.gz
tar -xvf nginx-1.16.0.tar.gz
cd nginx-1.16.0

3、配置并构建 Nginx

./configure \
--prefix=/usr/local \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module \
--with-http_image_filter_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-mail \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module \
--with-google_perftools_module \
--with-cpp_test_module \
--with-compat \
--with-pcre \
--with-pcre-jit \
--with-libatomic \
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' \
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' \
--add-dynamic-module=../ngx_http_geoip2_module
make
sudo make install

查看 Nginx 是否安装成功

nginx -v

nginx version: nginx/1.16.0

4、创建 nginx 用户

groupadd nginx
useradd -g nginx nginx

5、创建 nginx cache 文件夹

mkdir /var/cache/nginx

6、配置 nginx.service

sudo vi /usr/lib/systemd/system/nginx.service

复制粘贴:

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

7、启用 GeoIP2 模块(可选)

编辑 /etc/nginx/nginx.conf 文件

在 events 之前加入:

load_module /usr/lib64/nginx/modules/ngx_http_geoip2_module.so;

在 http 内加入以下代码:

#/usr/share/GeoIP/GeoIP2-Country.mmdb 替换为实际路径
geoip2 /usr/share/GeoIP/GeoIP2-Country.mmdb {
    auto_reload 60m;
    $geoip2_metadata_country_build metadata build_epoch;
    $geoip2_data_country_code country iso_code;
    $geoip2_data_country_name country names en;
}

#/usr/share/GeoIP/GeoIP2-City.mmdb 替换为实际路径
geoip2 /usr/share/GeoIP/GeoIP2-City.mmdb {
    auto_reload 60m;
    $geoip2_data_city_name city names en;
}

fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
fastcgi_param COUNTRY_NAME $geoip2_data_country_name;
fastcgi_param CITY_NAME    $geoip2_data_city_name;

8、启动 nginx 服务

systemctl start nginx
systemctl enable nginx

解决 error: the HTTP XSLT module requires the libxml2/libxslt 错误

yum -y install libxml2 libxml2-dev
yum -y install libxslt-devel

解决 error: the HTTP image filter module requires the GD library. 错误

yum -y install gd-devel

解决 error: the GeoIP module requires the GeoIP library. 错误

yum -y install GeoIP GeoIP-devel GeoIP-data

解决 error: the Google perftools module requires the Google perftools 错误

yum -y install gperftools

解决 error: libatomic_ops library was not found. 错误

yum -y install libuuid-devel libblkid-devel libudev-devel fuse-devel libedit-devel libatomic_ops-devel

解决 error trying to exec 'cc1plus': execvp: No such file or directory 错误

yum -y install gcc-c++

解决 error: [pool www] cannot get uid for user 'www-data' 错误

groupadd www-data
useradd -g www-data www-data

解决configure: error: mbed TLS libraries not found. 错误。

需要安装mbedtls,教程:https://www.24kplus.com/linux/281.html

解决 error: Cannot find OpenSSL's <evp.h> 错误

yum install openssl openssl-devel
ln -s /usr/lib64/libssl.so /usr/lib/

解决 error: Libtool library used but 'LIBTOOL' is undefined 错误

yum install libtool

解决 exec: g++: not found 错误

yum -y update gcc
yum -y install gcc+ gcc-c++

解决 configure: error: tss lib not found: libtspi.so 错误

yum install trousers-devel

解决 Can't exec "autopoint": No such file or directory 错误

yum install gettext gettext-devel gettext-common-devel

解决 configure: error: libcrypto not found. 错误

yum remove openssl-devel
yum -y install openssl-devel

解决 configure: error: Package requirements (libffi >= 3.0.0) were not met: No package 'libffi' found 错误

yum install libffi-devel

解决 fatal error: uuid.h: No such file or directory 错误

yum install e2fsprogs-devel uuid-devel libuuid-devel

解决 configure: error: openssl lib not found: libcrypto.so 错误

yum install openssl-devel

解决 tar (child): lbzip2: Cannot exec: No such file or directory 错误

yum -y install bzip2

解决 configure: error: C++ preprocessor "/lib/cpp" fails sanity check 错误

yum install gcc-c++

解决 configure: error: Please reinstall the BZip2 distribution 错误

yum install bzip2 bzip2-devel

解决 configure: error: cURL version 7.15.5 or later is required to compile php with cURL support 错误

yum install curl-devel

解决 configure: error: not found. Please provide a path to MagickWand-config or Wand-config program 错误

yum install ImageMagick-devel

解决 configure: error: no acceptable C compiler found in $PATH 错误

yum install gcc

解决 configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met: 错误

yum install libicu-devel

解决 configure: error: Package requirements (sqlite3 > 3.7.4) were not met: No package 'sqlite3' found 错误

yum install sqlite-devel

解决 configure: error: Package requirements (oniguruma) were not met: No package 'oniguruma' found 错误

yum install oniguruma oniguruma-devel

注意:.NET Core仅支持64位系统。

1、添加 dotnet repos

在安装.NET之前,需要注册 Microsoft key,注册 repos 并安装所需的依赖项。

打开 terminal 并运行以下命令:

sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm

2、 安装 .NET SDK

在 terminal 中,运行以下命令:

sudo yum update
sudo yum install dotnet-sdk-2.2

官方英文原文:https://dotnet.microsoft.com/download/linux-package-manager/centos/sdk-current