怎么制作营销网站,服装公司网站首页,外网访问群晖wordpress,洛阳企业网站建设【系统软件03】centos7安装和使用node-v18.16.0#xff08;centos7升级glibc 2.28#xff09; 前言#xff1a;本文是解决node 18.16.0的依赖问题#xff0c;具体的node安装流程#xff0c;可以参考我的另外一篇文章。一、下载node v18.16.0二、下载glibc2.28#xff08;… 【系统软件03】centos7安装和使用node-v18.16.0centos7升级glibc 2.28 前言本文是解决node 18.16.0的依赖问题具体的node安装流程可以参考我的另外一篇文章。一、下载node v18.16.0二、下载glibc2.28建议使用第二个第一个很慢的二、升级glibc2.28前置条件三、查看本机的gcc版本、make版本四、升级gcc4.91、源码编译安装——(不建议使用)2、devtoolset安装升级gcc4.9不建议使用2.1、devtoolset在线安装2.1、devtoolset离线下载、安装 3、gcc 7.3建议 五、升级make4.1.0六、现在可以安装glibc了七、安装glibc可能会遇到的问题问题0重新启动后发现右击桌面打不开terminal了问题一Centos 7 升级 Glibc-2.28,报错问题二、cannot access /var/lib/alternatives/gcc: No such file or directory问题三、我usr/bin/gcc还存在着4.8版本 前言本文是解决node 18.16.0的依赖问题具体的node安装流程可以参考我的另外一篇文章。
linux环境下安装nodejs和npm的两个方法
一、下载node v18.16.0
下载地址https://nodejs.org/dist/https://nodejs.org/en/download/releases 解压查看node版本号 [dev1localhost bin]$ ./node -v ./node: /lib64/libm.so.6: version GLIBC_2.27 not found (required by ./node) ./node: /lib64/libc.so.6: version GLIBC_2.25’ not found (required by ./node) ./node: /lib64/libc.so.6: version GLIBC_2.28 not found (required by ./node) ./node: /lib64/libstdc.so.6: version CXXABI_1.3.9’ not found (required by ./node) ./node: /lib64/libstdc.so.6: version GLIBCXX_3.4.20 not found (required by ./node) ./node: /lib64/libstdc.so.6: version GLIBCXX_3.4.21’ not found (required by ./node) 错误原因 查看本机GLIBC版本 strings /lib64/libc.so.6 |grep GLIBC [dev1localhost bin]$ strings /lib64/libc.so.6 |grep GLIBC
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
GLIBC_PRIVATE
___sys_nerr_GLIBC_2_3
___sys_nerr_GLIBC_2_4
___sys_nerr_GLIBC_2_1
___sys_errlist_GLIBC_2_1
___sys_errlist_GLIBC_2_4
___sys_errlist_GLIBC_2_3
_IO_file_seekoffGLIBC_2.2.5
getservent_rGLIBC_2.2.5
_sys_siglistGLIBC_2.3.3
_dl_starting_upGLIBC_PRIVATE
tmpfileGLIBC_2.2.5
sched_getaffinityGLIBC_2.3.3
pthread_cond_waitGLIBC_2.2.5
regexecGLIBC_2.2.5
memcpyGLIBC_2.14
_IO_file_initGLIBC_2.2.5
realpathGLIBC_2.2.5
realpathGLIBC_2.3
__ctype32_tolowerGLIBC_2.2.5
gethostbyname2_rGLIBC_2.2.5
getaliasbyname_rGLIBC_2.2.5
_IO_file_overflowGLIBC_2.2.5
pthread_cond_waitGLIBC_2.3.2
getprotoent_rGLIBC_2.2.5
regexecGLIBC_2.3.4
_rtld_globalGLIBC_PRIVATE
getgrgid_rGLIBC_2.2.5
pthread_cond_initGLIBC_2.2.5
_IO_fsetposGLIBC_2.2.5
GLIBC_2.8
_IO_proc_closeGLIBC_2.2.5
_sys_nerrGLIBC_2.12
pthread_cond_timedwaitGLIBC_2.3.2
__libc_enable_secureGLIBC_PRIVATE
pcloseGLIBC_2.2.5
getaliasent_rGLIBC_2.2.5
__tls_get_addrGLIBC_2.3
_sys_nerrGLIBC_2.4
sys_sigabbrevGLIBC_2.2.5
pthread_cond_broadcastGLIBC_2.2.5
_IO_proc_openGLIBC_2.2.5
posix_spawnGLIBC_2.15
getpwnam_rGLIBC_2.2.5
_rtld_global_roGLIBC_PRIVATE
getrpcbyname_rGLIBC_2.2.5
pthread_cond_broadcastGLIBC_2.3.2
nftw64GLIBC_2.2.5
_sys_siglistGLIBC_2.2.5
_sys_nerrGLIBC_2.3
_IO_fsetpos64GLIBC_2.2.5
__ctype_tolowerGLIBC_2.2.5
__ctype_toupperGLIBC_2.2.5
_IO_file_underflowGLIBC_2.2.5
localeconvGLIBC_2.2.5
pthread_cond_timedwaitGLIBC_2.2.5
_IO_file_fopenGLIBC_2.2.5
__ctype_bGLIBC_2.2.5
GLIBC_2.5
_IO_file_finishGLIBC_2.2.5
GLIBC_2.9
getgrnam_rGLIBC_2.2.5
GLIBC_2.7
GLIBC_2.6
getservbyname_rGLIBC_2.2.5
__ctype32_bGLIBC_2.2.5
_resGLIBC_2.2.5
__secure_getenvGLIBC_2.2.5
getnetent_rGLIBC_2.2.5
nftwGLIBC_2.2.5
getpwuid_rGLIBC_2.2.5
_IO_fdopenGLIBC_2.2.5
posix_spawnGLIBC_2.2.5
gethostbyaddr_rGLIBC_2.2.5
_IO_file_xsputnGLIBC_2.2.5
pthread_attr_initGLIBC_2.2.5
getrpcbynumber_rGLIBC_2.2.5
_IO_fopenGLIBC_2.2.5
getnetbyname_rGLIBC_2.2.5
memcpyGLIBC_2.2.5
pthread_cond_signalGLIBC_2.3.2
pthread_cond_signalGLIBC_2.2.5
sys_sigabbrevGLIBC_2.3.3
_IO_fgetposGLIBC_2.2.5
posix_spawnpGLIBC_2.15
_IO_file_setbufGLIBC_2.2.5
getservbyport_rGLIBC_2.2.5
_sys_errlistGLIBC_2.3
_IO_file_attachGLIBC_2.2.5
gethostent_rGLIBC_2.2.5
_sys_errlistGLIBC_2.4
_sys_nerrGLIBC_2.2.5
nftw64GLIBC_2.3.3
_IO_fgetpos64GLIBC_2.2.5
__res_maybe_initGLIBC_PRIVATE
fnmatchGLIBC_2.2.5
h_errnoGLIBC_PRIVATE
_sys_errlistGLIBC_2.12
_IO_fcloseGLIBC_2.2.5
gethostbyname_rGLIBC_2.2.5
_IO_do_writeGLIBC_2.2.5
getspent_rGLIBC_2.2.5
getpwent_rGLIBC_2.2.5
pthread_cond_destroyGLIBC_2.2.5
sched_setaffinityGLIBC_2.3.3
getspnam_rGLIBC_2.2.5
sched_setaffinityGLIBC_2.3.4
_IO_popenGLIBC_2.2.5
getgrent_rGLIBC_2.2.5
_IO_file_syncGLIBC_2.2.5
GLIBC_2.11
GLIBC_2.16
GLIBC_2.10
pthread_cond_initGLIBC_2.3.2
GLIBC_2.17
getprotobyname_rGLIBC_2.2.5
GLIBC_2.13
getnetbyaddr_rGLIBC_2.2.5
_sys_errlistGLIBC_2.2.5
_IO_file_writeGLIBC_2.2.5
pthread_cond_destroyGLIBC_2.3.2
nftwGLIBC_2.3.3
GLIBC_2.2.6
fopencookieGLIBC_2.2.5
__ctype32_toupperGLIBC_2.2.5
sched_getaffinityGLIBC_2.3.4
_dl_argvGLIBC_PRIVATE
posix_spawnpGLIBC_2.2.5
getrpcent_rGLIBC_2.2.5
getprotobynumber_rGLIBC_2.2.5
_IO_file_close_itGLIBC_2.2.5
_obstackGLIBC_2.2.5
[dev1localhost bin]$ 可以看到我们centos7上安装的GLIBC版本是2.2.5而node所需的GLIBC版本是GLIBC_2.27、GLIBC_2.25、GLIBC_2.28 所以报错的原因是glibc版本过低
解决方案升级glibc
二、下载glibc2.28建议使用第二个第一个很慢的
http://ftp.gnu.org/pub/gnu/glibc/ http://www.gnu.org/software/libc/libc.html http://mirrors.nju.edu.cn/gnu/libc/ http://ftp.ntu.edu.tw/gnu/glibc/ http://mirrors.syringanetworks.net/gnu/libc/ http://alpha.gnu.org/gnu/glibc/
链接https://blog.csdn.net/wmzjzwlzs/article/details/127478144
二、升级glibc2.28前置条件
查看升级glibc2.28所需编译器的版本号 我们查看安装包内的文件INSTALL显示如下
Recommended Tools for Compilation
We recommend installing the following GNU tools before attempting to
build the GNU C Library:* GNU make 4.0 or newerAs of relase time, GNU make 4.2.1 is the newest verified to workto build the GNU C Library.* GCC 4.9 or newerGCC 4.9 or higher is required. 可知需要make4.0以后的版本最新验证过的make版本是4.2.1可知需要gcc4.9或者更新版本。
三、查看本机的gcc版本、make版本
gcc-4.8.2
[dev1localhost build]$ gcc -v
使用内建 specs。
COLLECT_GCCgcc
COLLECT_LTO_WRAPPER/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标x86_64-redhat-linux
配置为../configure --prefix/usr --mandir/usr/share/man --infodir/usr/share/info --with-bugurlhttp://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threadsposix --enable-checkingrelease --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-stylegnu --enable-languagesc,c,objc,obj-c,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tunegeneric --with-arch_32x86-64 --buildx86_64-redhat-linux
线程模型posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
[dev1localhost build]$make
[dev1localhost build]$ make -v
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
[dev1localhost build]$ 四、升级gcc4.9
1、源码编译安装——(不建议使用)
下载 gcc-4.9.0.tar.bz2 wget https://mirrors.ustc.edu.cn/gnu/gcc/gcc-4.9.0/gcc-4.9.0.tar.bz2解压
tar -jxvf gcc-4.9.0.tar.bz2进入gcc-4.9.0目录
cd gcc-4.9.0下载所需
./contrib/download_prerequisites创建build目录、进入build目录 mkdir build cd buildconfigure
../configure --enable-checkingrelease --enable-languagesc,c --disable-multilib
../configure --prefix/usr/local/gcc --enable-bootstrap --enable-checkingrelease --enable-languagesc,c --disable-multilib编译、安装 make -j4 sudo make install导出环境变量 [dev1localhost ~]$ sudo vi /etc/profile.d/gcc.sh
export PATH/usr/local/gcc/bin:$PATH
[dev1localhost ~]$ source /etc/profile.d/gcc.sh
[dev1localhost ~]$ gcc -v
使用内建 specs。
COLLECT_GCCgcc
COLLECT_LTO_WRAPPER/usr/local/gcc/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
目标x86_64-unknown-linux-gnu
配置为../configure --prefix/usr/local/gcc --enable-bootstrap --enable-checkingrelease --enable-languagesc,c --disable-multilib
线程模型posix
gcc 版本 4.9.0 (GCC)
[dev1localhost ~]$黑猴子的家Centos 7.x gcc 4.8.5 升级到 gcc 4.9.4 源码安装GCC-4.9.2
2、devtoolset安装升级gcc4.9不建议使用
2.1、devtoolset在线安装
升级到gcc4.9
sudo yum update
wget https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtoolset-3.repo --no-check-certificate
yum -y install devtoolset-3-gcc devtoolset-3-gcc-c devtoolset-3-binutils
scl enable devtoolset-3 bash2.1、devtoolset离线下载、安装
离线下载-devtoolset
sudo yum update
wget https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtoolset-3.repo --no-check-certificate
sudo yum install --downloadonly devtoolset-3 --downloaddirdevtoolset-3 --skip-broken离线安装-devtoolset
cd devtoolset-3
sudo rpm -Uvh --force *.rpm如果报错
错误依赖检测失败libqudamath 4.8.5 - 39.el7 被 已安装 libgfortran - 4.8.5 - 39.el7.x86_64下面的解决方案不建议使用因为可能会引起重启系统失败。所以建议的解决方案是——使用离线安装的centos系统制作离线版本的devtoolset,然后再拷贝到局域网安装。 原因和解决方案
这个错误表示在安装某个软件包时Yum 检测到系统中已经存在 libgfortran但它的版本与所需版本不匹配。具体来说安装程序需要的是 libqudamath 4.8.5-39.el7但系统中已经安装的 libgfortran 是 4.8.5-39.el7.x86_64因此无法满足依赖关系。为了解决这个问题可以按以下步骤操作卸载已安装的 libgfortran。
首先需要卸载系统中已经安装的 libgfortran。使用以下命令可以查看已安装的 libgfortran 版本rpm -qa | grep libgfortran
然后使用以下命令卸载指定版本的 libgfortransudo rpm -e --nodeps libgfortran-4.8.5-39.el7.x86_64
其中--nodeps 选项表示忽略依赖关系检查强制删除软件包。这里需要将命令中的版本号替换为实际安装的版本。使用devtoolset
临时使用
scl enable devtoolset-3 bash或者
source /opt/rh/devtoolset-3/enable当前账户永久使用 ~/.profile文件假如以下内容
source /opt/rh/devtoolset-3/enable所有账户永久使用 打开/etc/profile.d/devtoolset.sh 文件 把以下内容加入文件
source /opt/rh/devtoolset-3/enable其他版本参靠为CentOS 6、7升级gcc至4.8、4.9、5.2、6.3、7.3等高版本
升级到gcc 7.3
yum -y install centos-release-scl
yum -y install devtoolset-7-gcc devtoolset-7-gcc-c devtoolset-7-binutils
scl enable devtoolset-7 bash
需要注意的是scl命令启用只是临时的退出shell或重启就会恢复原系统gcc版本。
如果要长期使用gcc 7.3的话echo source /opt/rh/devtoolset-7/enable /etc/profile
升级到gcc 8.3
yum -y install centos-release-scl
yum -y install devtoolset-8-gcc devtoolset-8-gcc-c devtoolset-8-binutils
scl enable devtoolset-8 bash
需要注意的是scl命令启用只是临时的退出shell或重启就会恢复原系统gcc版本。
如果要长期使用gcc 8.3的话echo source /opt/rh/devtoolset-8/enable /etc/profile
升级到gcc 9.3
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c devtoolset-9-binutils
scl enable devtoolset-9 bash
需要注意的是scl命令启用只是临时的退出shell或重启就会恢复原系统gcc版本。
如果要长期使用gcc 9.3的话echo source /opt/rh/devtoolset-9/enable /etc/profile再说一下已经停止支持的devtoolset4(gcc 5.2)及之前版本的安装方法升级到gcc 4.8
wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtoolset-2.repo
yum -y install devtoolset-2-gcc devtoolset-2-gcc-c devtoolset-2-binutils
scl enable devtoolset-2 bash
升级到gcc4.9
wget https://copr.fedoraproject.org/coprs/rhscl/devtoolset-3/repo/epel-6/rhscl-devtoolset-3-epel-6.repo -O /etc/yum.repos.d/devtoolset-3.repo
yum -y install devtoolset-3-gcc devtoolset-3-gcc-c devtoolset-3-binutils
scl enable devtoolset-3 bash
升级到gcc 5.2
wget https://copr.fedoraproject.org/coprs/hhorak/devtoolset-4-rebuild-bootstrap/repo/epel-6/hhorak-devtoolset-4-rebuild-bootstrap-epel-6.repo -O /etc/yum.repos.d/devtoolset-4.repo
yum install devtoolset-4-gcc devtoolset-4-gcc-c devtoolset-4-binutils -y
scl enable devtoolset-4 bash
升级完成后一定要运行gcc --version 看一下版本号变成升级后的gcc版本才算升级成功。3、gcc 7.3建议
gcc73之前的在某些系统上安装处理依赖会有些问题所以建议从7.3开始使用。一般高版本的对低版本的会做兼容处理如果你真的一定要4.9建议前面两种方法但是中间可能会有相关问题且源码编译的时间特别长
升级到gcc 7.3
yum -y install centos-release-scl
yum -y install devtoolset-7-gcc devtoolset-7-gcc-c devtoolset-7-binutils
scl enable devtoolset-7 bash
需要注意的是scl命令启用只是临时的退出shell或重启就会恢复原系统gcc版本。
如果要长期使用gcc 7.3的话echo source /opt/rh/devtoolset-7/enable /etc/profile重启后生效
五、升级make4.1.0 下载、构建、安装 wget http://mirrors.ustc.edu.cn/gnu/make/make-4.3.tar.gz
$ tar -xzvf make-4.3.tar.gz
$ cd make-4.3/
# 创建构建目录
mkdir build cd build
# 安装到指定目录
$ ../configure --prefix/usr/local/make
$ make -j4 sudo make install
# 创建软链接
$ cd /usr/bin/
$ mv make make.bak # backup
$ ln -sv /usr/local/make/bin/make /usr/bin/make验证
[dev1localhost bin]$ make -v
GNU Make 4.2.1
为 x86_64-pc-linux-gnu 编译
Copyright (C) 1988-2016 Free Software Foundation, Inc.
许可证GPLv3GNU 通用公共许可证第 3 版或更新版本http://gnu.org/licenses/gpl.html。
本软件是自由软件您可以自由修改和重新发布它。
在法律允许的范围内没有其他保证。
[dev1localhost bin]$Centos 7 升级 Glibc-2.28
六、现在可以安装glibc了
# 在线安装
wget http://mirrors.ustc.edu.cn/gnu/libc/glibc-2.28.tar.gz
# 解压
tar zxf glibc-2.28.tar.gz
cd glibc-2.28
mkdir build
cd build../configure --prefix/usr --disable-profile --enable-add-ons --with-headers/usr/include --with-binutils/usr/bin --disable-sanity-checks --disable-werror
# 这步执行时间依赖你的配置我的4核虚拟机大概30多分钟
make -j8
make install
sudo make localedata/install-locales验证
ls -l /lib/libc.so.6You should restart this script from your build directory after youve
fixed all problems!
Btw. the script doesnt work if youre installing GNU libc not as your
primary library!
make[1]: *** [Makefile:111: install] Error 1
make[1]: Leaving directory /home/dev1/下载/glibc-2.28
make: *** [Makefile:12install] 错误 2
[rootlocalhost build]# ls -l /lib64/libc.so.6
lrwxrwxrwx. 1 root root 12 Jun 8 22:45 /lib64/libc.so.6 - libc-2.28.so
[rootlocalhost build]# 到此就完成了如果你遇到了其他问题可以继续往后看看是否有你需要的。
七、安装glibc可能会遇到的问题
问题0重新启动后发现右击桌面打不开terminal了
原因你应该是没有进行下面的这行没安装字符集 sudo make localedata/install-locales 在glibc-2.28/build/目录下执行上面的命令行。 而且开机还有下面这个问题其实选择哪个都不行的只有用上面的命令行安装了字符集才可以打开 open terminal 原因可以查看INSTALL文件 解决方案用moba xterm链接然后执行上面的这行。
问题一Centos 7 升级 Glibc-2.28,报错 collect2: error: ld returned 1 exit status execution of gcc -B /usr/bin/ failed /usr/bin/ld: cannot find -lnss_test2
collect2: error: ld returned 1 exit status
Execution of gcc -B/usr/bin/ failed!
The script has found some problems with your installation!
Please read the FAQ and the README file and check the following:
- Did you change the gcc specs file (necessary after upgrading fromLinux libc5)?
- Are there any symbolic links of the form libXXX.so to old libraries?Links like libm.so - libm.so.5 (where libm.so.5 is an old library) are wrong,libm.so should point to the newly installed glibc file - and there should beonly one such link (check e.g. /lib and /usr/lib)
You should restart this script from your build directory after youve
fixed all problems!
Btw. the script doesnt work if youre installing GNU libc not as your
primary library!
make[1]: *** [Makefile:111: install] Error 1
make[1]: Leaving directory /home/dev1/下载/glibc-2.28
make: *** [Makefile:12: install] Error 2
[rootlocalhost build]# ls -l /lib/libc.so.6
在 CentOS 7 上升级 Glibc 到 2.28 版本时如果遇到了 collect2: error: ld returned 1 exit status 错误并伴随着类似于 “execution of gcc -B /usr/bin/ failed” 的错误消息可能是由于编译器路径配置不正确导致的。
这个错误通常是由于编译器的路径设置不正确引起的。在升级 Glibc 后系统中的编译器可能需要重新配置以适应新的 Glibc 版本。
要解决此问题可以尝试以下步骤 检查编译器路径 确保系统中的编译器路径正确配置。可以使用 which gcc 命令查看当前使用的 gcc 编译器的路径。确保该路径存在且指向正确的位置。 更新编译器配置 如果编译器路径不正确可以尝试更新编译器的配置。可以使用 update-alternatives 命令来配置系统中的默认编译器。例如使用以下命令将 gcc 编译器设置为默认
which gcc
sudo update-alternatives --set gcc /usr/bin/gcc-版本号如果没有带版本号的gcc,则采用如下方案
sudo update-alternatives --set gcc /usr/bin/gcc将 “版本号” 替换为正确的 gcc 版本号。
重新编译程序 如果编译器路径已正确配置但仍然出现错误请尝试重新编译您的程序。在重新编译之前确保更新了相关的头文件和库文件以适应新的 Glibc 版本。 除了上面这个方案我还有个想法就是gcc备份下然后建立一个软连接原理上应该是可行的未验证。 [dev1localhost bin]$ which gcc /opt/rh/devtoolset-7/root/usr/bin/gcc [dev1localhost bin]$ 创建软链接 $ cd /usr/bin/ $ mv gccgcc.bak # backup $ ln -sv /opt/rh/devtoolset-7/root/usr/bin/gcc /usr/bin/gcc 大家可以尝试下进行后继续进行libc的编译和安装。 问题二、cannot access /var/lib/alternatives/gcc: No such file or directory 如果在执行 update-alternatives 命令时出现错误提示 /var/lib/alternatives/gcc: No such file or directory这通常表示该命令无法找到 gcc 的备用链接。 其实我的gcc在目录/usr/local/gcc/bin/gcc
如果您的 gcc 安装在 /usr/local/gcc/bin/gcc 路径下而不是系统默认的 /usr/bin/gcc您可以按照以下步骤使用 update-alternatives 命令来配置备用链接
确认 gcc 是否已正确安装运行以下命令来检查 gcc 是否已安装在系统上
which gcc
/usr/local/gcc/bin/gcc --version如果显示 gcc 的版本信息则表示已正确安装。
设置备用链接运行以下命令来设置 gcc 的备用链接
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc/bin/gcc 10上述命令将 /usr/local/gcc/bin/gcc 添加到备用链接列表中并将其优先级设置为 10。您可以根据需要调整优先级的值。
选择默认的 gcc运行以下命令来选择默认的 gcc
sudo update-alternatives --config gcc这会列出所有可用的 gcc 选项并要求您选择默认的 gcc。输入对应的序号然后按 Enter 键进行选择。
完成以上步骤后gcc 的备用链接将被正确配置为 /usr/local/gcc/bin/gcc。您可以再次运行 gcc --version 来验证配置是否生效。
请注意在使用非默认路径的 gcc 时确保在编译和构建过程中使用正确的编译器路径。您可能需要相应地更新项目的构建脚本或 Makefile以指定正确的 gcc 路径。
问题三、我usr/bin/gcc还存在着4.8版本
[dev1localhost bin]$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc/bin/gcc 1
[sudo] password for dev1:
failed to link /usr/bin/gcc - /etc/alternatives/gcc: /usr/bin/gcc exists and it is not a symlink
如果在尝试设置备用链接时出现 /usr/bin/gcc 存在且不是符号链接的错误提示可能是由于该路径下已存在名为 /usr/bin/gcc 的文件。
要解决此问题可以尝试以下方法
备份并删除现有文件 首先将现有的 /usr/bin/gcc 文件备份到其他位置然后删除它。可以使用以下命令完成
sudo mv /usr/bin/gcc /usr/bin/gcc_backup
sudo rm /usr/bin/gcc重新设置备用链接 重新运行设置备用链接的命令确保备用链接指向正确的 gcc 可执行文件
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc/bin/gcc 10选择默认 gcc 运行以下命令来选择默认的 gcc
sudo update-alternatives --config gcc然后从可用的选项中选择正确的 gcc并按 Enter 键进行确认。
完成上述步骤后应该能够重新设置备用链接并成功使用新版本的 gcc。
如果问题仍然存在可能涉及其他配置或系统设置问题。建议您咨询 CentOS 社区或寻求专业的系统管理员支持以获得更具体的帮助和指导。
http://192.168.4.77:8899/c/4a4a4981-bcbf-4333-b79a-c00c1c5048dc
/usr/bin/gcc has not been configured as an alternative for gcc