9

In my Ubuntu there is g++ --version -

g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I want to have same g++ --version on another Linux machine which has -

g++ (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

How can I alter my g++ version to be the same as the above?

Peachy
  • 7,117
  • 10
  • 38
  • 46
URL87
  • 215

2 Answers2

5

Download the g++-4.1 version from here. g++-4.1 is not available in the recent Ubuntu repositories. So you need to download the package from the link provided.

Install/compile the download package alongside with the current version of g++.

Then use update-alternatives to switch version

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10

Change the default version by choosing the appropriate version:

sudo update-alternatives --config g++
devav2
  • 36,312
  • Other versions could be available via apt-get, like sudo apt-get install g++-6. Then a whereis g++-6 could be used to find its location and change update-alternatives appropriately. – boomkin Feb 05 '19 at 09:08
  • the link is dead – stiv Feb 12 '20 at 16:46
  • @stiv Do you really need g++ 4.1? Well since Lucid Lynk reached EOL in 2013/2015 and once a release reached EOL, the package information is removed from ubuntu packages. – Kulfy Feb 12 '20 at 17:54
  • More details here and here. That latter uses the source from gnu.org. – Guser314 Feb 15 '20 at 17:30
0

Personally I wouldn't revert to an earlier version of g++ unless there was no other possible way to achieve my desired results. g++ is available for all supported versions of Ubuntu in the repository and can be installed with sudo apt install g++ If you do indeed need multiple versions you'll want to utilize How to choose the default gcc and g++ version? as @boomkin indicated in this comment.

Elder Geek
  • 36,023
  • 25
  • 98
  • 183
  • apt get install g++-7 doesn't allow to install specific version, like 7.2, the question is exactly how, step by step, install specific g++ version if installing g++-7 gives a wrong one – stiv Feb 13 '20 at 20:06
  • @stiv Personally I wouldn't revert to an earlier version of g++ unless there was no other possible way to achieve my desired results. What is it you are attempting to accomplish? – Elder Geek Feb 18 '20 at 14:01