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?

Rinzwind
  • 309,379

5 Answers5

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

WitchCraft
  • 1,904
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
ams
  • 3,089
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
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.

Plexo
  • 11
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/

tommyk
  • 4,556