Skip to content

Alternatives

Example

alternatives --install /usr/bin/java java /user2/jdk1.5.0_14/bin/java 0
환경설정에 JDK 추가
alternatives --config java
JDK 확인
alternatives --remove java /user2/jdk1.5.0_14/bin/java
JDK 제거.
alternatives --display java
설치된 JAVA 출력.

Change GCC Version

Ubuntu에서 GCC버전을 변경하는 방법은 아래와 같다:

First erased the current update-alternatives setup for gcc and g++:

$ sudo update-alternatives --remove-all gcc 
$ sudo update-alternatives --remove-all g++

Install Packages:

It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:

$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test 
$ sudo apt-get update
$ sudo apt-get install gcc-4.9 g++-4.9
$ sudo apt-get install gcc-5 g++-5

Install Alternatives:

Symbolic links cc and c++ are installed by default. We will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively.

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 30

$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 10
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 30

$ sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 100
$ sudo update-alternatives --set cc /usr/bin/gcc

$ sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 100
$ sudo update-alternatives --set c++ /usr/bin/g++

Configure Alternatives:

The last step is configuring the default commands for gcc, g++. It's easy to switch between 4.3 and 4.4 interactively:

$ sudo update-alternatives --config gcc
$ sudo update-alternatives --config g++

Python to Python3

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 30
$ sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 30

See also

Favorite site