23

I have Ubuntu 10.04 32-bit with gcc 4.4.3 currently installed on it. I want to upgrade it to gcc/g++ 4.7 (I am looking for C++ 0x support)

How to update using Ubuntu Package Manager:

apt-get upgrade/install ??

As a second option I downloaded the latest gcc snapshot file from:

http://gcc.cybermirror.org/snapshots/LATEST-4.7/gcc-4.7-20110709.tar.bz2

Would doing

./configure
make  
make install 

on this package build and install it from source?

4

5 Answers 5

15

12.04

Add the toolchain ppa test repository, then do apt-get update, and apt-get dist-upgrade

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.7 c++-4.7

This is only available in 12.04 - older ubuntu versions cannot be updated to this same version using this method.

See here for further information about PPAs
https://help.launchpad.net/Packaging/PPA

6
  • 1
    you mean sudo apt-get install gcc-4.7 c++-4.7? There must be something wrong because typing "gcc --version" after doing that still returns 4.6.3
    – user2413
    Jul 5, 2012 at 11:15
  • 1
    @user2413 this installs g++4.7 as a separate program and you could use g++-4.7 *.cpp; what you may want is sudo apt-get upgrade
    – manuzhang
    Feb 12, 2013 at 12:01
  • Worked for me on 10.04, without the c++-4.7 part.
    – Ajith
    Apr 8, 2013 at 9:42
  • 1
    WARNING: It work for me on quantal (12.10), but it removed acroread, valgrind no longer works and I couldn't attach gdb to a running process.
    – sehe
    Sep 7, 2013 at 14:49
  • 1
    Watch out, check the section The following packages will be REMOVED. On Ubuntu 10.04 the install g++4.7 command above wanted to remove 100s of packages including my xserver, gnome desktop, eclipse, chrome, xulrunner, etc...
    – jcalfee314
    Feb 10, 2014 at 0:56
4
sudo apt-get install gcc-snapshot

Then, invoke it with:

/usr/lib/gcc-snapshot/bin/gcc

For the second part of the question, the answer is "yes, sort of". If you really want to do that (i.e. installing the gcc-snapshot package isn't enough) then you'll need to install the dependencies:

sudo apt-get build-dep gcc-snapshot

Then, find the correct configure options:

gcc -v

(and modify the install path etc.)

Then, build like this:

mkdir objdir
cd objdir
../gcc-src-dir/configure ......insert..options..here...
make
make install
2
  • BTW, if you do build from source, expect problems linking crti.o. Search other questions here for solutions how to fix that.
    – ams
    Nov 15, 2011 at 15:16
  • 1
    In 10.04 this instructions bring gcc-4.5 (not 4.6 or 4.7), as reported by /usr/lib/gcc-snapshot/bin/gcc -v
    – alfC
    Dec 14, 2011 at 7:48
1

10.04 LTS

Use the following command to install add-apt-repository:

apt-get install python-software-properties

Then add the tooclain ppa test repo as described for 12.04 LTS.

1
  • 1
    This seems to be saying to install the package that provides the Software Sources window, then once you have that, you can go ahead and use the Software Sources window to add the PPA. But the Software Sources window certainly does exist in 10.04; you don't have to install anything to get it! Also, the method this refers to for adding the PPA doesn't require opening the Software Sources window or using the GUI at all. @Plexo, can you explain further or expand on this? Jun 17, 2012 at 9:15
1

How to install gcc 4.8 on Ubuntu 10.04:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update; sudo apt-get install gcc-4.8 g++-4.8

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Verify gcc version with:

g++ --version

It worked on my machine. Source: http://ubuntuhandbook.org/index.php/2013/08/install-gcc-4-8-via-ppa-in-ubuntu-12-04-13-04/

1

How to compile the latest gcc:

apt-get update && apt-get -qq --no-install-recommends install build-essential git grep \
  && mkdir gcc-latest && cd gcc-latest \
  && git init && git remote add origin git://gcc.gnu.org/git/gcc.git \
  && git fetch --depth=1 --tags --no-recurse-submodules --quiet \
  && git tag -l | grep '^releases/gcc' | sort --version-sort --field-separator=- -k2 | tail -1 | xargs git checkout \
  && ./contrib/download_prerequisites && ./configure --disable-multilib && make -j 4 && make install

What the script above does is:

  • Install/update the tools needed to compile the latest gcc, such as make, old-stable gcc et cetera;
  • Prepare a playground (directory) gcc-latest;
  • Find the version of the latest gcc and download it;
  • Configure the environment, compile and install gcc.

BTW. If you are running this script on a low-end VPS with little RAM space, remember to allocate enough swap space just before you run gcc compilation/installation script:

dd if=/dev/zero of=/swapfile bs=100M count=20 \
  && chmod 0600 /swapfile \
  && mkswap /swapfile \
  && swapon /swapfile \
  && echo "swapon /swapfile" >> /etc/rc.local

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .