APT source of GCC on Ubuntu

On Ubuntu 14.04, we can use APT to get and install software. However APT needs source which is a server contains the software.

And Ubuntu has a default source list at /etc/apt/source.list . But some software is not here. For example, different versions of GCC.

If you want to add some new source to the ubuntu, actally you add it to this list.

So here we add GCC source to APT source list.

1. add source

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update

2. check different GCC versions from the source

>sudo apt-cache search gcc

chunxie@chunxie-VirtualBox:~$ sudo apt-cache search gcc | grep gcc-6
gcc-6-base - GCC, the GNU Compiler Collection (base package)
gcc-6 - GNU C compiler
gcc-6-plugin-dev - Files for GNU GCC plugin development.
gcc-6-test-results - Test results for the GCC test suite
libgcc-6-dev - GCC support library (development files)
gcc-6-multilib - GNU C compiler (multilib support)
lib32gcc-6-dev - GCC support library (32 bit development files)
gcc-6-doc - Documentation for the GNU compilers (gcc, gobjc, g++)
gcc-6-locales - GCC, the GNU compiler collection (native language support files)
gcc-6-source - Source of the GNU Compiler Collection
libx32gcc-6-dev - GCC support library (x32 development files)
lib64gcc-6-dev - GCC support library (64bit development files)
chunxie@chunxie-VirtualBox:~$ sudo apt-cache search gcc | grep gcc-7
gcc-7-base - GCC, the GNU Compiler Collection (base package)
gcc-7 - GNU C compiler
gcc-7-multilib - GNU C compiler (multilib support)
gcc-7-plugin-dev - Files for GNU GCC plugin development.
gcc-7-test-results - Test results for the GCC test suite
lib32gcc-7-dev - GCC support library (32 bit development files)
libgcc-7-dev - GCC support library (development files)
gcc-7-doc - Documentation for the GNU compilers (gcc, gobjc, g++)
gcc-7-locales - GCC, the GNU compiler collection (native language support files)
gcc-7-source - Source of the GNU Compiler Collection
libx32gcc-7-dev - GCC support library (x32 development files)
gcc-7-offload-nvptx - GCC offloading compiler to NVPTX
lib64gcc-7-dev - GCC support library (64bit development files)

3. install different version of gcc as you like

>sudo apt-get install gcc-6

chunxie@chunxie-VirtualBox:~$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc /usr/share/man/man1/gcc.1.gz
chunxie@chunxie-VirtualBox:~$ ls /usr/bin/gcc
/usr/bin/gcc
chunxie@chunxie-VirtualBox:~$ ls /usr/bin/gcc*
/usr/bin/gcc      /usr/bin/gcc-ar-4.8  /usr/bin/gcc-nm-6
/usr/bin/gcc-4.8  /usr/bin/gcc-ar-6    /usr/bin/gcc-ranlib
/usr/bin/gcc-6    /usr/bin/gcc-nm      /usr/bin/gcc-ranlib-4.8
/usr/bin/gcc-ar   /usr/bin/gcc-nm-4.8  /usr/bin/gcc-ranlib-6

Here we can see gcc-6 installed. And gcc-4.8 is already here.

4. set default GCC

>sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20

>sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50

Now we can check if the configure.

>sudo update-alternatives --query gcc

chunxie@chunxie-VirtualBox:/usr/bin$ sudo update-alternatives --query gcc
[sudo] password for chunxie: 
Name: gcc
Link: /usr/bin/gcc
Status: auto
Best: /usr/bin/gcc-6
Value: /usr/bin/gcc-6

Alternative: /usr/bin/gcc-4.8
Priority: 20

Alternative: /usr/bin/gcc-6
Priority: 50

let's try gcc here:

chunxie@chunxie-VirtualBox:/usr/bin$ gcc --version
gcc (Ubuntu 6.5.0-2ubuntu1~14.04.1) 6.5.0 20181026
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

it works. 

So now let's do all for gcc-ar,gcc-nm,gcc-ranlib and g++ as:

chunxie@chunxie-VirtualBox:/usr/bin$ sudo update-alternatives --install /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-6 50
update-alternatives: using /usr/bin/gcc-ranlib-6 to provide /usr/bin/gcc-ranlib (gcc-ranlib) in auto mode
chunxie@chunxie-VirtualBox:/usr/bin$ sudo update-alternatives --install /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-4.8 20

Done for GCC.

 

How about ARM GCC? I don't find the source for linaro or PPA. Anyone can share it for me? if Linaro or PPA has it.

Answer this question, WSL shows APT source of gcc-arm packages:

gcc-7-alpha-linux-gnu - GNU C compiler
gcc-7-alpha-linux-gnu-base - GCC, the GNU Compiler Collection (base package)
gcc-7-arm-linux-gnueabi - GNU C compiler
gcc-7-arm-linux-gnueabi-base - GCC, the GNU Compiler Collection (base package)
gcc-7-cross-base-ports - GCC, the GNU Compiler Collection (library base package)

gcc-6-arm-linux-gnueabi - GNU C compiler
gcc-6-arm-linux-gnueabi-base - GCC, the GNU Compiler Collection (base package)
gcc-6-arm-linux-gnueabihf - GNU C compiler
gcc-6-arm-linux-gnueabihf-base - GCC, the GNU Compiler Collection (base package)

Maybe it because WSL is ubuntu 18. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值