I'm still on Ubuntu 22.04 LTS but needed g++14. The sudo apt-get gcc-14 did not work for me, as it installed clang++14 for some reason (perhaps a misconfiguration on my part). What did work for me was following the instructions I found at https://www.dedicatedcore.com/blog/install-gcc-compiler-ubuntu/
The steps I took:
sudo apt install build-essential
sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y
wget https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.gz
tar -xf gcc-14.1.0.tar.gz
cd gcc-14.1.0
./configure -v --build=$(uname -m)-linux-gnu --host=$(uname -m)-linux-gnu --target=$(uname -m)-linux-gnu --prefix=/usr/local/gcc-14.1.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib --program-suffix=-14.1.0
make
sudo make install
And if you would like to make it the default:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/gcc-14.1.0/bin/g++-14.1.0 14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-14.1.0/bin/gcc-14.1.0 14
After that, g++ showed I was running version 14.1.0. I was then able to compile my project that included some c++20/23 features that were not in the previous versions of g++ (chrono/format).
Videos
I'm still on Ubuntu 22.04 LTS but needed g++14. The sudo apt-get gcc-14 did not work for me, as it installed clang++14 for some reason (perhaps a misconfiguration on my part). What did work for me was following the instructions I found at https://www.dedicatedcore.com/blog/install-gcc-compiler-ubuntu/
The steps I took:
sudo apt install build-essential
sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y
wget https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.gz
tar -xf gcc-14.1.0.tar.gz
cd gcc-14.1.0
./configure -v --build=$(uname -m)-linux-gnu --host=$(uname -m)-linux-gnu --target=$(uname -m)-linux-gnu --prefix=/usr/local/gcc-14.1.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib --program-suffix=-14.1.0
make
sudo make install
And if you would like to make it the default:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/gcc-14.1.0/bin/g++-14.1.0 14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-14.1.0/bin/gcc-14.1.0 14
After that, g++ showed I was running version 14.1.0. I was then able to compile my project that included some c++20/23 features that were not in the previous versions of g++ (chrono/format).
GCC-14 (and G++-14) is available in the Universe repository for Ubuntu 24.04, as evident in the Ubuntu Package archive.
It is equally evident that this package is not available for Ubuntu 22.04, so installing this on 22.04 will require some third-party interference, or you have to compile it yourself.
See here on how to enable the Universe repositories.
I recently started learning and then I realized I needed a GCC so my C code can run but I am having a lot of problems trying to download it
I saw somebody link to this old post today. The best way to install GCC in homebrew right now is just brew install gcc. If you have the XCode Command Line Tools (they are separate from XCode; you can install them with xcode-select --install) installed, a precompiled version will be installed (which is very fast).
Homebrew solution
To answer my own question, homebrew-versions now has a fairly up to date formula of GCC. It can be installed using
brew install [flags] https://raw.github.com/Homebrew/homebrew-versions/gcc48.rb
Where [flags] should include all the required languages, e.g. (--enable-cxx --enable-fortran).
This will install the executables with a suffix, i.e. gcc has to be accessed as gcc-version to avoid clashes. If necessary, one can create appropriate symlinks to make this version the default.
Manual installation
Alternatively, an up-to-date GCC (as of the time of writing) can be compiled manually using the following shell script:
VERSION=4.7.0
PREFIX=/usr/gcc-$(VERSION)
LANGUAGES=c,c++,fortran
MAKE=make
# Or
# MAKE='make -j 4' # to compile using four cores
brew-path() { brew info $1 | head -n3 | tail -n1 | cut -d' ' -f1; }
# Prerequisites
brew install gmp
brew install mpfr
brew install libmpc
# Download & install the latest GCC
mkdir -p $PREFIX
mkdir temp-gcc
cd temp-gcc
wget ftp://ftp.gnu.org/gnu/gcc/gcc-$VERSION/gcc-$VERSION.tar.gz
tar xfz gcc-$VERSION.tar.gz
rm gcc-$VERSION.tar.gz
cd gcc-$VERSION
mkdir build
cd build
../configure \
--prefix=$PREFIX \
--with-gmp=$(brew-path gmp) \
--with-mpfr=$(brew-path mpfr) \
--with-mpc=$(brew-path libmpc) \
--program-suffix=-$VERSION \
--enable-languages=$LANGUAGES \
--with-system-zlib \
--enable-stage1-checking \
--enable-plugin \
--enable-lto \
--disable-multilib
$MAKE bootstrap
make install
# Uncomment for cleanup …
# cd ../../..
# rm -r temp-gcc
This will stage GCC into the path /usr/gcc-4.7.0. Now all you need to do is either create symlinks to the executables or add the bin directory to the $PATH variable.
If you want to install it as a local user
GNU GSRC provides an easy way to do so
Link: http://www.gnu.org/software/gsrc/
After configuration, simply specify the following commands:
cd gsrc
make -C pkg/gnu/gcc
make -C pkg/gnu/gcc install
The second step could also be changed to speed up for an N-core system:
make -C pkg/gnu/gcc MAKE_ARGS_PARALLEL="-jN"
You can run the configure script with the --prefix parameter: ../gcc-4.5.0/configure --prefix=/home/foo/bar. Since it is very likely that the c++ standard library is different then the one on your system, you have to set export LD_LIBRARY_PATH=/home/foo/bar/lib before you can start a program compiled by this compiler.
You cannot install gcc in virtualenv — gcc is not a Python package. And you don't need to — Python virtual environments are used to separately install Python packages so you don't need a separate gcc in a virtual env.
If you really need to install a separate, non-system gcc, you probably need bigger virtualization solution — a container or a virtual machine.
I know this is a pretty old question, but bumping in if anyone gets caught here. Now, we could install gcc/g++ in a virtual conda environment using the following command. To install GCC:
conda install -c conda-forge gcc
and to install G++:
conda install -c conda-forge gxx
yum install centos-release-scl-rh
yum install devtoolset-3-gcc devtoolset-3-gcc-c++
update-alternatives --install /usr/bin/gcc-4.9 gcc-4.9 /opt/rh/devtoolset-3/root/usr/bin/gcc 10
update-alternatives --install /usr/bin/g++-4.9 g++-4.9 /opt/rh/devtoolset-3/root/usr/bin/g++ 10
For installing the system compilers gcc, g++, the install command is # yum install gcc-c++ → Provides version 4.8.5 : /usr/bin/{ gcc, g++ }.
Other options: 1. gcc53-c++-5.3.0-1.el6.x86_64.rpm → https://drive.google.com/file/d/0B7S255p3kFXNRm9FVnZYUnhyZzg/view?usp=sharing&resourcekey=0-1N6zQa6Sbl_WycG1O9I7JA : Download and install : # cd Downloads/ && yum install ./gcc53-c++-5.3.0-1.el6.x86_64.rpm ..... Provides /usr/bin/{gcc53, g++53}.
- The devtoolset´s : https://www.softwarecollections.org/en/scls/rhscl/devtoolset-6/ →
# yum-config-manager --enable rhel-server-rhscl-7-rpms
Install gcc, g++ version 4.9.2 : # yum install devtoolset-3-gcc-c++
Note : You can have as many gcc/g++ versions as you want, installed at the same time. ( The system compilers are a must.)
- gcc49-c++-4.9.3-1.el6.x86_64.rpm https://drive.google.com/file/d/1Pwq1ua80dGM72i7rpDNAIIdfcR1WK-hG/view?usp=sharing → Provides
/usr/bin/{gcc49, g++49}.
gcc63-c++-6.3.0-1.el7.x86_64.rpm https://drive.google.com/file/d/1t4WrgvpEP-6_NN3qMJhz9MS3CJhHrHKc/view?usp=sharing → Provides
/usr/bin/{gcc63, g++63}.gcc45-c++-4.5.4-1.el7.x86_64.rpm https://drive.google.com/file/d/15aRg-BPhuyaEyZA9Jy-iAyC21_pwN7nD/view?usp=sharing → Provides
/usr/bin/{gcc45, g++45, gfortran45}gcc42-c++-4.2.4-1.el6.x86_64.rpm https://drive.google.com/file/d/1eYWk6Nd63xeqqAUoJldNWRuwEGO6cAyv/view?usp=sharing → Provides
/usr/bin/{gcc42, g++42}
gcc73-c++-7.3.0-1.el7.x86_64.rpm https://drive.google.com/file/d/1PgwCP5tu8D0EJbJVTqJd7Vg8dJ4l4noi/view?usp=sharing → Provides
/usr/bin/{gcc73, g++73}gcc48-c++-4.8.5-1.el6.x86_64.rpm https://drive.google.com/file/d/1w6fW6oSflDDYZt_cOpGj3QMEmzUC8Q9L/view?usp=sharing → Provides
/usr/bin/{gcc48, g++48, gfortran48}gcc84-c++-8.4.0-1.el7.x86_64.rpm https://drive.google.com/file/d/1xgFtsiDi2uiB1B0AcOaSpxVizzET-pJf/view?usp=sharing → Provides
/usr/bin/{gcc84, g++84, gfortran84}
gcc-7 and gcc-8 will happily co-live together.
I would suggest to let gcc-7 be installed, for satisfying build-essential and perhaps other dependent packages, and configure gcc-8 to be your default gcc installation.
Use update-alternatives for having gcc redirected automatically to gcc-8:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 700 --slave /usr/bin/g++ g++ /usr/bin/g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8
This will give you the convenience of gcc being at the latest version, and still you will be able to invoke gcc-7 or gcc-8 directly.
If you'll wish to change the default gcc version later on, run sudo update-alternatives --config gcc. It will bring a prompt similar to this, which lets you pick the version to be used:
There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-8 800 auto mode
1 /usr/bin/gcc-7 700 manual mode
2 /usr/bin/gcc-8 800 manual mode
Press <enter> to keep the current choice[*], or type selection number:
The higher priority is the one that is picked automatically by update-alternatives.
Master table of all GCC versions for each Ubuntu
At: How do I use the latest GCC on Ubuntu?
GCC 8 on Ubuntu 16.04
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-8 g++-8
gcc-8 --version
gives 8.1.0 as of 2018-11. See also:
GCC 9 on Ubuntu 19.04
sudo apt install gcc-9
https://packages.ubuntu.com/search?keywords=gcc-9
I wanted to install gcc-6 alongside my existing installation of gcc-9 and this is how I did it. First off, sudo apt install gcc-6 didn't work because the package wasn't found so I had to add a new repository that contained gcc-6. To do this, I first found a repository that contains gcc-6 from Google and ended up at: https://packages.ubuntu.com/bionic/gcc-6
From there, I chose an architecture (amd64) which took me to a page with all the mirrors. I added the first mirror (mirrors.kernel.org/ubuntu) to /etc/apt/sources.list and did sudo apt update and then installed gcc-6 with sudo apt install gcc-6.
To switch between gcc versions, I used the following:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 6
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9
sudo update-alternatives --config g++
You need to use the equals sign instead of the colon.
sudo apt-get install gcc=4:8.2.0-1ubuntu1
You'll also need to update your default gcc config.
How to change the default GCC compiler in Ubuntu?