Update g++ version on CentOS

Source: Internet
Author: User
Tags echo command

I recently had to use the C + + version of the Open Source library for stuttering, because it recommended using the gcc4.6 version, so I had to upgrade my gcc.

Luckily I was upgrading on the CentOS, and CentOS on it, and the easiest way was to upgrade to the g++4.7 version. Let's talk about how to upgrade g++:

Open the terminal, and then enter the following command:

CD/ETC/YUM.REPOS.D
wget http://people.centos.org/tru/devtools/devtools.repo 
Yum--enablerepo= Testing-devtools-6 Install devtoolset-1.0
The three-line command above indicates that the installation is complete. Note that Devtoolset is actually a package that includes GCC, GDB, binutils, Elfutils, SystemTap, Valgrind, Oprofile, and DWZ.

If you only need to install GCC, then you can specify only GCC:

Yum-y--enablerepo=testing-1.1-devtools-6 Install DEVTOOLSET-1.0-GCC devtoolset-1.0-gcc-c++

Since CentOS is generally used as a server, we generally do not change the GCC version easily. So the directory installed here is:/opt/centos/devtoolset-1.0/root/. You can see that there are a lot of files in it.

To start using g++, you must export its path, so continue typing in the terminal:

Export path=/opt/centos/devtoolset-1.0/root/usr/bin/: $PATH


After export, you can try the g++ version now. In the terminal, enter:

g++--version


This is the terminal output is:

g++ (GCC) 4.7.0 20120507 (Red Hat 4.7.0-5)
Copyright (C) Free Software Foundation, Inc.
This is free software; The source for copying conditions.  There is NO
warranty, not even to merchantability or FITNESS for A particular.
If you want to keep using this version of g++, you can set the g++ to the system's environment variable. But be careful, it can lead to dependency problems. The methods of modification are:

Method 1: Use the/opt/centos/devtoolset-1.0/root to enable file

Echo ' source/opt/centos/devtoolset-1.1/enable ' >> ~/.bash_profile

source/opt/centos/devtoolset-1.1/ Enable

It is recommended that you set the script '/opt/centos/devtoolset-1.0/enable ' By default environment variables given by GCC, and add it to the environment variables that require the user.


Method 2: Modify profile file:

#vi/etc/profile
In the inside add:

Export path= "/opt/centos/devtoolset-1.0/root/usr/bin/: $PATH"


Method 3: Modify the. bashrc file:

# VI/ROOT/.BASHRC
In the inside add:

Export path= "/opt/centos/devtoolset-1.0/root/usr/bin/: $PATH"

Note: These 3 methods generally need to unregister the system or source before it takes effect, and finally you can test it by using the echo command:
# echo $PATH
See if there is already a/opt/centos/devtoolset-1.0/root/usr/bin/this path in the output.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.