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).
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.
linux - how to install gcc-12 on ubuntu - Stack Overflow
Is installing GCC on Linux as complicated as I think it is?
g++ - How to install g++12 on Ubuntu 20.04? - Unix & Linux Stack Exchange
c++ - Install gcc on linux with no root privilege - Stack Overflow
Does GCC come pre-installed on Ubuntu?
How do I fix "gcc: command not found" on Ubuntu?
Why does "unable to locate package gcc-14" appear on Ubuntu?
Videos
gcc-12 is not available in ubuntu 20.04, so we need to compile it from source code, here are the steps which I borrowed from this video:
- Step 1: clone gcc source code and checkout gcc-12 branch
$ git clone https://gcc.gnu.org/git/gcc.git gcc-source
$ cd gcc-source/
$ git branch -a
$ git checkout remotes/origin/releases/gcc-12
- Step 2: make another build dir
Note this is important as running ./configure from within the source directory is not supported as documented here.
$ mkdir ../gcc-12-build
$ cd ../gcc-12-build/
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
- Step 3: installing GCC prequisites and run configure again
The missing libraries will be shown in above ./confgiure output, search and install them one by one.
$ apt-cache search MPFR
$ sudo apt-get install libmpfrc++-dev
$ apt-cache search MPC | grep dev
$ sudo apt-get install libmpc-dev
$ apt-cache search GMP | grep dev
$ sudo apt-get install libgmp-dev
$ sudo apt-get install gcc-multilib
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
An alternative is to run the download_prerequisites script.
cd gcc-source/
$ ./contrib/download_prerequisites
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
- Step 4: compile gcc-12
$ make -j16
Still flex is missing:
$ sudo apt-get install flex
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
$ make -j16
$ make install
Another way is to use Ubuntu 22.04 where gcc-12 is available. In Ubuntu 22.04, gcc-12 can be installed with apt:
$ sudo apt install gcc-12
You can use Homebrew to install pre-built binaries. Follow instructions to install Homebrew at https://brew.sh/, then
brew install gcc for default GCC (currently 11) or brew install gcc@12 for gcc-12.
Note that it may compile missing dependencies.
Disclaimer: I am not well versed at Linux at all. Please pardon my ignorance.
I'm trying to figure out how to install GCC onto my macbook running Ubuntu 16.04. However after reading through the 6 steps to install GCC outlined on the GCC website I am at a total loss. I understand maybe 50% of the words on these pages. There are so many prerequisites and so many software requirements and so many technical things you have to set up that there is basically no hope in me figuring this out unless I extensively google every other word within the instructions. I would like to install it myself without the use of some sort of installer, but if it's this complicated to do so then I may have quite a bit of googling to do.
My question is this. What are the general guidelines I need to know to install GCC on Linux? I'm not asking for a "step-by-step how-to" guide. I'd just like a general overview on how one goes about installing GCC on their own. I understand I need some required software installed, I need to check and see if my physical CPU is compatible (real confusing), I need figure out in what directory I want to install GCC in, I need to figure out how to build GCC (this is real confusing) and I need to figure out a whole lotta stuff that I don't even know about yet. Perhaps it isn't as hard as it seems. Maybe this way of installing GCC is hard mode that nobody does. Or maybe this is the standard way that everyone uses. I don't know and would greatly appreciate any help or advice you all may have. Thanks!
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.