跳转至

Linux 软件安装

1 重要配置安装

1.1 安装中文手册

sudo apt-get install manpages-zh

2 gcc

如果无外网访问权限,第3步:下载安装依赖包失败,可以去http://gcc.gnu.org/pub/gcc/infrastructure/ 下载,具体下载什么,./contrib/download_prerequisites文件里面都有
  • 下载地址 主要设计以下操作,以 gcc-10.2.0 为例
  • 首先保证环境中已经有 g++、gcc 工具:yum install -y gcc gcc-c++
  • 解压包:tar -xzvf gcc-10.2.0.tar.gz
  • 下载安装依赖性:cd gcc-10.2.0;./contrib/download_prerequisites
  • 创建编译文件夹:mkdir build && cd build
  • 配置编译选项 (自定义安装路径):../configure --prefix=/opt/gcc-10.2.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib
  • 编译:make
  • 安装:sudo make install
  • 创建符号链接 注意:在步骤 4 配置选项中指定了安装路径/opt/gcc-10.2.0,这个路径可以任意,便于后期删除

2.1 下载安装依赖文件失败问题

  • 问题:文件 gmp-6.1.0.tar.bz2 isl-0.18.tar.bz2 mpc-1.0.3.tar.gz mpfr-3.1.4.tar.bz2 下载失败
  • 解决方法:
  • 手动下载并放入 gcc-10.2.0 文件夹中(gmp/mpc/mpfr下载地址
  • 编辑 ./contrib/download_prerequisites 配置,将里面 wget 此 3 个文件的命令用 # 注释,再执行 ./contrib/download_prerequisites

2.2 配置编译选项 (自定义安装位置) 后符号链接 gcc 方法

注意:以下内容用 src 代替安装路径 /opt/gcc-10.2.0 1. 执行步骤 2 时,指定 gcc 安装位置:../configure --prefix=/opt/gcc-10.2.0 指定了 gcc 安装位置在 /opt/gcc-10.2.0 下 2. 在执行完步骤 5,6 或,创建符号链接,在 /opt/gcc-10.2.0/bin 下新建 gcc-ln.sh 文件,输入以下内容

#!/bin/bash
#将/opt/gcc-10.2.0/bin/下二进制文件 符号链接到/usr/local/bin下,并且都加上后缀-10,
for file in *; do
  sudo ln -s /opt/gcc-12.1.0/bin/${file} /usr/local/bin/${file}
done
  1. 执行 gcc-ln.sh 文件
chmod u+x gcc-ln.sh
  1. 使用 gcc-10 或 g++-10 指令来编译 c 或 c++ 文件
$ g++-10 1.cpp
$ ./a.out
hello world!

2.3 删除 gcc

因为安装时指定了安装位置,也使用了符号链接二进制文件,因此只需要删除安装文件 /opt/gcc-10.2.0,同时创建的二进制符号链接也会消失

2.4 多版本共存切换方法

  • 编辑文件,命令 gcc-version-env,写入如下内容,其中 ROOT_PATH 是 configures --prefix 设置的安装目录
  • 切换版本时。source gcc-version-env 加载即可。
ROOT_PATH=/root/compile/env/gcc-4.8.5
export PATH=$ROOT_PATH/bin:$PATH
export CPATH=$ROOT_PATH/include:$CPATH
export LD_LIBRARY_PATH=$ROOT_PATH/lib:$ROOT_PATH/lib64:$LD_LIBRARY_PATH
export LIBRARY_PATH=$ROOT_PATH/lib:$ROOT_PATH/lib64:$LIBRARY_PATH

2.5 高版本 gcc 环境编译低版本 gcc 问题汇总

  • 参考 https://blog.csdn.net/llxxyy507/article/details/121070257

2.5.1 redeclared inline with 'gnu_inline' attribute

需要修改源码,具体参考如下: - gcc-git-commit-log - https://blog.csdn.net/code_back/article/details/107965773

2.5.2 LIBRARY_PATH variable... contains current directory

  • 错误信息
checking LIBRARY_PATH variable... contains current directory
configure: error: 
*** LIBRARY_PATH shouldn't contain the current directory when
*** building gcc. Please change the environment variable
*** and run configure again.
make[2]: *** [Makefile:3954: configure-stage1-gcc] Error 1
  • 原因:原因是不能给环境变量 LIBRARY_PATH 设置任何值
  • 解决方法:命令行执行 LIBRARY_PATH= 命令后再执行 make

2.6 libstdc++.so.6: version CXXABI_1.3.9 not found

  • 原因:(出现在高版本 gcc 编译低版本 gcc 场景下)编译后生成了 libstdc++.so.6 库,使当前的编译器链接了刚编译出来的而导致。
  • 解决方法:将编译出来的库符号链接 unlink,再链接到高版本的 libstdc++.so.6 上,重新编译。
  • make 错误输出
configure: error: in `/root/compile/packages/gcc-4.8.5/x86_64-unknown-linux-gnu/libsanitizer':
configure: error: C compiler cannot create executables
See `config.log' for more details.
make[2]: *** [Makefile:15933: configure-stage1-target-libsanitizer] Error 77
make[2]: Leaving directory '/root/compile/packages/gcc-4.8.5'
make[1]: *** [Makefile:21493: stage1-bubble] Error 2
make[1]: Leaving directory '/root/compile/packages/gcc-4.8.5'
make: *** [Makefile:892: all] Error 2
  • 查看 /root/compile/packages/gcc-4.8.5/x86_64-unknown-linux-gnu/libsanitizer 下的 config. log,在 94 行有如下错误:
/root/compile/packages/gcc-4.8.5/host-x86_64-unknown-linux-gnu/gcc/cc1: /root/compile/packages/gcc-4.        8.5/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6: version `CXXABI_1.3.9' not found         (required by /root/compile/packages/gcc-4.8.5/host-x86_64-unknown-linux-gnu/gcc/cc1)

2.6.1 error: ‘SIGSEGV’ was not declared in this scope return signum == SIGSEGV && flags ()->handle_segv;

  • 编辑 /root/compile/packages/gcc-4.8.5/x86_64-unknown-linux-gnu/libsanitizer/asan/asan_linux.cc,添加头文件 #include <signal.h>
../../.././libsanitizer/asan/asan_linux.cc: In function ‘bool __asan::AsanInterceptsSignal(int)’:
../../.././libsanitizer/asan/asan_linux.cc:95:20: error: ‘SIGSEGV’ was not declared in this scope
   return signum == SIGSEGV && flags()->handle_segv;
                    ^
../../.././libsanitizer/asan/asan_linux.cc:96:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make[4]: *** [Makefile:441: asan_linux.lo] Error 1
make[4]: Leaving directory '/root/compile/packages/gcc-4.8.5/x86_64-unknown-linux-gnu/libsanitizer/asan'

2.6.2 error: ‘statp’ was not declared in this scope

进入到 /root/compile/packages/gcc-4.8.5/x86_64-unknown-linux-gnu/libsanitizer/tsan,再进入 ../../.././libsanitizer/tsan/,编辑 tsan_platform_linux.cc 的 295 行,__res_state *statp = (__res_state*)state; 改成 struct __res_state *statp = (struct __res_state*)state;

../../.././libsanitizer/tsan/tsan_platform_linux.cc:295:16: error: ‘statp’ was not declared in this scope
   __res_state *statp = (__res_state*)state;
                ^
../../.././libsanitizer/tsan/tsan_platform_linux.cc:295:37: error: expected primary-expression before ‘)’ token
   __res_state *statp = (__res_state*)state;
                                     ^
../../.././libsanitizer/tsan/tsan_platform_linux.cc:295:38: error: expected ‘;’ before ‘state’
   __res_state *statp = (__res_state*)state;
                                      ^
make[4]: *** [Makefile:475: tsan_platform_linux.lo] Error 1
make[4]: Leaving directory '/root/compile/packages/gcc-4.8.5/x86_64-unknown-linux-gnu/libsanitizer/tsan'
make[3]: *** [Makefile:326: all-recursive] Error 1

3 glibc

  • 下载地址: http://ftp.gnu.org/gnu/glibc/
  • 编译步骤:解压源码后执行如下指令
# cd 解压目录
mkdir build
cd build
../configure --prefix=/env/glibc
make 
make install

3.1 问题汇总

3.1.1 LD_LIBRARY_PATH shouldn't contain the current directory

将 LD_LIBRARY_PATH 环境变量置空,执行 export LD_LIBRARY_PATH=

3.1.2 makedb.c:849:3: error: ‘security_context_t’ is deprecated [-Werror=deprecated-declarations]

  • 错误日志:
makedb.c:849:3: error: ‘security_context_t’ is deprecated [-Werror=deprecated-declarations]
   security_context_t ctx;
   ^~~~~~~~~~~~~~~~~~
makedb.c:863:3: error: ‘matchpathcon’ is deprecated: Use selabel_lookup instead [-Werror=deprecated-declarations]
   if (matchpathcon (outname, S_IFREG | mode, &ctx) == 0 && ctx != NULL)
   ^~
  • 修改编译选项,禁止此错误 -Wno-deprecated-declarations,编辑构建目录下的 config.make 文件, 查找 CFLAGS, 在后面添加 -Wno-deprecated-declarations
CFLAGS = -g -O2 -Wno-deprecated-declarations

4 cmake

[root@centos7 ~]# wget https://github.com/Kitware/CMake/releases/download/v3.24.0/cmake-3.24.0.tar.gz
[root@centos7 ~]# tar -xzf cmake-3.24.0.tar.gz
[root@centos7 ~]# cd cmake-3.24.0
[root@centos7 cmake-3.24.0]# ./bootstrap 
[root@centos7 cmake-3.24.0]# make
[root@centos7 cmake-3.24.0]# make install

5 cheat

title: cheat是什么?
允许您在命令行上创建和查看交互式备忘单。它的设计目的是帮助提醒 * nix 系统管理员他们经常使用的命令的选项,但是频率不足以记住。

5.1 Linux 安装

  • 项目地址:
    • https://github.com/cheat/cheat
    • https://github.com/cheat/cheatsheets
  • 官方安装文档
  • 安装步骤:
  • 下载 cheat 安装
cd /tmp \
  && wget https://github.com/cheat/cheat/releases/download/4.2.5/cheat-linux-amd64.gz \
  && gunzip cheat-linux-amd64.gz \
  && chmod +x cheat-linux-amd64 \
  && sudo mv cheat-linux-amd64 /usr/local/bin/cheat
  1. 配置 cheat:首次使用 cheat,如首次使用 cheat netstat,会提示生成 cheat 配置文件和下载 cheatsheets
[root@centos7 ~]# cheat netstat
A config file was not found. Would you like to create one now? [Y/n]: Y
Would you like to download the community cheatsheets? [Y/n]: Y
Cloning community cheatsheets to /root/.config/cheat/cheatsheets/community.
正克隆到 '/root/.config/cheat/cheatsheets/community'...
  1. 可以选择自定义 cheat 配置 conf.yml

6 压缩软件安装

6.1 zip、unzip

  • zip:yum install -y zip
  • unzip:yum install -y unzip

6.2 bzip2

  • yum install -y bzip2