简体   繁体   中英

How to install previous version (4.4.7) of gcc/g++ via apt-get in ubuntu 14.04?

Due to legacy issues I have to install the gcc/g++ version 4.4.7 in my current Ubuntu-gnome 14.04 32 bit virtual machine.

The default update via apt-get install is the 4.8.2 which is a "no go" work for this project. I've removed it (apt-get remove) . The downloaded and tried to install the 4.4.7 source but it requires to many dependencies.

Via apt-get install I've tried doing:

sudo apt-get install gcc-4.4

The download/install is quite fast and when checkign gcc version it give indication that no gcc is installed to run the

sudo apt-get install gcc

If I do this I'll get the 4.8version.

All above also applies to g++.

I compiled the code with the following flag which solved the problem:

g++-4.4.7

It compiles for a specific version. (in this case 4.4.7)

To install a specific version use sudo apt-get install package=version . Or use synaptic package manager which allows you to install specific versions.

If you are trying to install an older version of GCC that is no longer available (ie gcc 4.9) on ubuntu, you will not be able to download it directly.

Open your /etc/apt/sources.list file and append the following two lines:

deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe

If this is your first time installing versioning on GCC run:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test

Then in your terminal run the installation for any versions you are attempting to add. For example, if you want to install 4.9 (outdated) alongside gcc 7 and gcc 8 (not outdated):

Sources: How to install GCC Compiler on Ubuntu 18.04 I need to install gcc4.9 on ubuntu 20.04|matlab mex

sudo apt update
sudo apt install gcc-4.9 g++ 4.9 gcc-7 g++-7 gcc-8 g++-8

Next, configure the GCC alternatives and their priority level:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 49 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gcov gcov /usr/bin/gcov-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcov gcov /usr/bin/gcov-8

To compile your code using one of the newly installed versions, simply specify at compile time:

g++-4.9 <file_name>.cpp

To set your default GCC compiler use:

sudo update-alternatives --config gcc

Note: If this is your first time installing any version of GCC you may need to run

sudo apt install build-essential
sudo apt-get install manpages-dev

Sources: How to install GCC Compiler on Ubuntu 18.04 I need to install gcc4.9 on ubuntu 20.04|matlab mex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM