【发布时间】:2016-07-08 23:39:53
【问题描述】:
我在 Ubuntu 16.04 上安装了多个版本的 gcc,我想知道如何设置系统以使用最新版本的 gcc 而无需卸载旧版本。
我更喜欢它是一个简单的脚本而不是依赖项,因为我将它安装在 Docker 容器中并且我不想让它膨胀。
【问题讨论】:
我在 Ubuntu 16.04 上安装了多个版本的 gcc,我想知道如何设置系统以使用最新版本的 gcc 而无需卸载旧版本。
我更喜欢它是一个简单的脚本而不是依赖项,因为我将它安装在 Docker 容器中并且我不想让它膨胀。
【问题讨论】:
# list everything in /usr/bin
# leave the ones that start with gcc
# remove everything but the version numbers
# remove anything but the numbers
# sort them
# get the last one
version=$(ls /usr/bin/ | grep '^gcc' | cut -d'-' -f2 | grep -o '[0-9]\+\(\.[0-9]\+\)\?' | sort | tail -n 1)
# remove the symbolic link to the current version of gcc
rm /usr/bin/gcc
# remove the symbolic link to the current version of g++
rm /usr/bin/g++
# create symbolic links to the latest versions
ln -s /usr/bin/g++-${version} /usr/bin/g++
ln -s /usr/bin/gcc-${version} /usr/bin/gcc
【讨论】: