8

I am using ubuntu 9.10 and it comes with gcc 4.4. How can I install gcc 4.5 without screwing up my gcc 4.4. environment. I just need gcc 4.5 to compile 1 application.

Thank you.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
michael
  • 106,540
  • 116
  • 246
  • 346
  • I suspect this could be better answered on SuperUser.com . – Carl Smotricz Apr 23 '10 at 19:30
  • Googling for this question brings me here. Nice. I was about to ask it myself. Unfortunately I still find the ways explained in both answers to difficult. As it was asked in apr/23, maybe someone has a better answer by now for gcc 4.6? – DrBeco Mar 28 '11 at 03:46
  • @Dr Beco: Building from source has worked fine for me. – HighCommander4 May 12 '11 at 18:17

2 Answers2

2

My preferred method is to have a deb-src entry in /etc/apt/sources.list as e.g.

# Debian sources
deb-src http://ftp.us.debian.org/debian/ unstable main contrib non-free

I can then do apt-get source foo and fetch the appropriate package with its sources which will be unpackages. I typically add a local changelog entry (set apart by a revision number as 1.2-3local0) and rebuild. This sometimes entails building dependencies. It all depends...

I guess gcc-4.5 is currently in experimental as per this page so you would have to add experimental to the sources.list file as well. I have not used this but it should work too:

deb-src http://ftp.debian.org/debian experimental main
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • But who can I switch back and forth between 4.4 and 4.5? – michael Apr 23 '10 at 19:51
  • They simply co-exists on your system as the currently available gcc-4.3 and gcc-4.4 do, plus older ones you may have from prior Ubuntu installations. You can use the dpkg-alternatives mechanism to override the default priorities, and / or create shall aliases or links in /usr/local/bin. – Dirk Eddelbuettel Apr 23 '10 at 20:08
  • And as an update now almost a year later, you also have `gcc-4.5` and `g++-4.5` .... – Dirk Eddelbuettel Mar 22 '11 at 22:57
0

The easiest way is to install into a private prefix:

configure --prefix=/some/private/prefix   ...

In a private prefix, there is 0 chance you'll overwrite an existing file. You'll then need to add the prefix to your path.

A second option is to give the new binaries a suffix and to use version specific runtime libraries:

configure --program-suffix=-4.5.0 --enable-version-specific-runtime-libs

although I can't promise some other file won't be modified.

R Samuel Klatchko
  • 74,869
  • 16
  • 134
  • 187
  • It works by having this packaged installed in a new directory. Since all files are installed within the new directory, there is no chance of conflict. It does require you to add the new directory to your path when you want to use the new binary (`PATH=/some/private/prefix/bin:${PATH}`). – R Samuel Klatchko Apr 23 '10 at 19:39
  • I assume you suggest me to download and compile gcc 4.5 myself. But my concern is it may need another set of dependencies? – michael Apr 23 '10 at 19:52
  • @michael - yes, gcc has a few dependencies (see http://gcc.gnu.org/install/prerequisites.html). The ones you are most likely to need are GMP, MPFR and MPC. Install all of them into a single private prefix. – R Samuel Klatchko Apr 23 '10 at 20:44