oczkoisse
oczkoisse

Reputation: 1641

Switch between different GCC versions

I recently built an older version of GCC and installed it in my home directory (spec. ~/local/gcc-5.3.0). However, I need this compiler only for CUDA projects, and will be working with the system compiler (GCC 6.2.1) rest of the time. So, I guess I need to find a way to switch between these as and when needed, and in a way that also changes the library and include paths appropriately.

I understand that update-alternatives is one way to do so, but it seems to require root permissions to be set up, which I don't have.

The next best thing might be to write a shell function in .bashrc that ensures the following:

Is the above the best way to achieve this? If so, what paths should I set while implementing such a function?

Upvotes: 6

Views: 5396

Answers (1)

yugr
yugr

Reputation: 21878

Is the above the best way to achieve this? If so, what paths should I set while implementing such a function?

As others pointed out, PATH and LD_LIBRARY_PATH are mandatory. You may also update MANPATH for completeness.

Rather than reinventing the wheel in .bashrc I suggest to employ a little known but extremely handy and modular Environment Modules that were designed for this specific purpose. You could use them like (once you set up config for gcc/3.1.1):

$ module load gcc/3.1.1
$ which gcc
/usr/local/gcc/3.1.1/linux/bin/gcc
$ module unload gcc
$ which gcc
gcc not found

Upvotes: 3

Related Questions