場景:收到開發需求,須要升級測試環境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