I'm trying to install g++ 5.x on an EC2 instance running Amazon Linux; in Amazon's central repository the latest version is 4.8.3. What configuration to can I make to allow yum
to find a newer gcc-c++ package?

- 505
- 3
- 14

- 478
- 1
- 4
- 13
-
1Did you ever figure this one out? I also need to install g++ 4.9 or higher – Chris Jan 24 '17 at 00:52
-
@Chris Herve published a working answer below (and that should be accepted) – Shlublu Oct 16 '18 at 08:40
6 Answers
Late to the party, but for those like me:
sudo yum install gcc72 gcc72-c++

- 1,293
- 8
- 18
-
6Loaded plugins: extras_suggestions, langpacks, priorities, update-motd No package gcc72 available. No package gcc72-c++ available. – PapaDiHatti Apr 08 '20 at 04:26
For Amazon Linux 2, you have to install the following
sudo yum install -y gcc-c++
It's a requirement to install some Ruby gems that need native extensions

- 12,964
- 9
- 77
- 164
Installing gcc5:
# Install required libraries
sudo yum install libmpc-devel mpfr-devel gmp-devel
# Gather source code
export GCC_VERSION=5.5.0
cd /tmp
curl -o "gcc-${GCC_VERSION}.tar.gz" \
https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc- ${GCC_VERSION}.tar.gz
tar xvzf "gcc-${GCC_VERSION}.tar.gz"
cd gcc-${GCC_VERSION}
# Configure and compile
./configure --with-system-zlib --disable-multilib --enable-languages=c,c++
make -j 8
# Install
sudo make install
Ensure /usr/local/bin/
is in your PATH
You may advantageously install version 7.3.0 released on 25th January 18 here

- 3,825
- 2
- 18
- 27
-
1`make -j 1` is better should you be using a `t2.micro`. 8 at a time kills it – Shlublu Oct 15 '18 at 16:43
-
Hey when I execute `make -j 8` command, It executed so may process but after some time I got Can not allocate memory error message and it also shows message that Waiting for unfinished jobs... . Can you please help me in this? – Sachin Shah Jul 20 '19 at 08:32
-
When I go in `tmp` and execute the step as you say. Now I didn't get that what is the role of `/usr/local/bin/` path. When is path comes in picture? – Sachin Shah Jul 20 '19 at 09:03
-
@SachinShah It is possible that the process differs now that AWS provide AmazonLinux 2 images. I haven't tried. Regarding the memory issue. Simply remove the `-j 8` option. – herve Aug 22 '19 at 12:27
-
@herve I have fixed that issue by expanding the instance size from t2.micro to t2.small. – Sachin Shah Aug 22 '19 at 17:48
You can run yum whatprovides g++
and it will output a list of different packages versions that provide the the g++
file.
example output:
...
gcc-c++-7.3.1-12.amzn2.x86_64 : C++ support for GCC
Repo : amzn2-core
Matched from:
Filename : /usr/bin/g++
gcc-c++-7.3.1-13.amzn2.x86_64 : C++ support for GCC
Repo : amzn2-core
Matched from:
Filename : /usr/bin/g++

- 146
- 1
- 6
On Amazon Linux 2 you can run sudo yum groupinstall "Development Tools"
which will install many compilers and dependencies including g++

- 2,260
- 18
- 27
Probably like "amazon linux ami release 2016.03", when you have gcc-4.8.3 . This OS is very close to CentOS 7.2 / RHEL 7.
Please try : # yum install centos-release-scl
If OK, you can do : # yum install devtoolset-4-gcc-c++
... and get g++, gcc version 5.2.1 .
Enabling "5.2.1" : $ scl enable devtoolset-4 bash
. Be aware that the setting is valid for the current terminal session only.
If any issues, I can supply a link to the four packages required for g++, gcc.

- 5,753
- 2
- 14
- 19