You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

如何在Ubuntu 16.04安装GCC 7.3?求可行替代升级方案

Hey there! Let's figure out how to install GCC 7.3 on Ubuntu 16.04, since we know the official Ubuntu Toolchain only offers 7.2 and Jonathan F's pre-built amd64 package is failing. Here are a couple of straightforward ways to get it done:

Installing GCC 7.3 on Ubuntu 16.04

Option 1: Compile from Source (Most Reliable)

Since working pre-built packages are hard to come by for this specific version and distro, compiling from source is a solid bet—and it's not as complicated as it sounds. Here's how:

  • First, install all the dependencies needed to build GCC:
    sudo apt update && sudo apt install -y build-essential libmpc-dev libmpfr-dev libgmp-dev flex bison
    
  • Download the GCC 7.3.0 source code from the official GNU GCC archives, then extract it and navigate into the source directory:
    tar -xf gcc-7.3.0.tar.gz
    cd gcc-7.3.0
    
  • Set up a separate build directory (keeps your source files clean) and configure the build. We'll install it to /usr/local/gcc-7.3 so it doesn't overwrite your system's default GCC:
    mkdir build && cd build
    ../configure --prefix=/usr/local/gcc-7.3 --enable-languages=c,c++ --disable-multilib
    
  • Start compiling. The -j$(nproc) flag uses all your CPU cores to speed things up—this might take 15-30 minutes depending on your hardware:
    make -j$(nproc)
    sudo make install
    
  • To use this GCC version by default, add it to your shell's PATH (skip this if you want to keep the system GCC as your default):
    echo 'export PATH=/usr/local/gcc-7.3/bin:$PATH' >> ~/.bashrc
    echo 'export LD_LIBRARY_PATH=/usr/local/gcc-7.3/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
    source ~/.bashrc
    
  • Verify the installation worked:
    gcc --version
    
    You should see output showing gcc (GCC) 7.3.0.

Option 2: Check for Alternative Third-Party PPAs

While Jonathan F's build is broken, there's a slim chance another trusted PPA has a working build. Before diving into compiling, you can try this quick check:

  • Install the tools needed to add PPAs:
    sudo apt install -y software-properties-common
    
  • Add the Ubuntu Toolchain test PPA (sometimes they have newer versions than the main repo, though it might still only have 7.2 for 16.04):
    sudo add-apt-repository ppa:ubuntu-toolchain-r/test
    sudo apt update
    
  • Try installing GCC 7.3:
    sudo apt install -y gcc-7.3 g++-7.3
    

If this works, great! If not, fall back to the source compilation method above—it's guaranteed to work as long as you have enough disk space and CPU power.


内容的提问来源于stack exchange,提问作者WillZ

火山引擎 最新活动