场景:收到开发需求,须要升级测试环境gcc版本python
一顿百度,基本百度的方案能够解决这个问题,可是我的以为安全起见须要多加个备份,因此写下blog纪录一下。c++
1.更换源下载安装新版本gccshell
cd /etc/yum.repos.d wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo yum --enablerepo=testing-devtools-2-centos-6 install devtoolset-2-gcc devtoolset-2-gcc-c++
会安装到/opt/rh/devtoolset-2/root/usr/bin目录下centos
2.备份老的gcc安全
简单的说一下脚本思路,其实用shell更容易,在学python,因此尽可能用起来ide
由于后面会将新目录下全部的执行文件替换到/usr/bin目录底下,因此以新目录底下的文件为基准,将/usr/bin目录下和新目录下同名的文件备份到Back_dir底下。测试
#!/usr/bin/python import os Dir="/opt/rh/devtoolset-2/root/usr/bin" Back_dir="/data/scripts/gcc_backup" if os.path.isdir(Back_dir): pass else: os.makedirs(Back_dir) for File in os.listdir(Dir): File_path="/usr/bin/"+File os.system('/bin/cp %s %s' % (File_path,Back_dir))
3.命令行执行cp命令替换可执行文件命令行
\cp -a /opt/rh/devtoolset-2/root/usr/bin/* /usr/bin
4.查看是否升级成功blog