Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Ubuntu, how do you install a newer version of python and keep the older python version?

Background:

  • I am using Ubuntu
  • The newer python version is not in the apt-get repository (or synaptic)
  • I plan on keeping the old version as the default python when you call "python" from the command line
  • I plan on calling the new python using pythonX.X (X.X is the new version).

Given the background, how do you install a newer version of python and keep the older python version?


I have downloaded from python.org the "install from source" *.tgz package. The readme is pretty simple and says "execute three commands: ./configure; make; make test; sudo make install;"

If I do the above commands, will the installation overwrite the old version of python I have (I definitely need the old version)?

like image 828
Trevor Boyd Smith Avatar asked Jun 16 '10 03:06

Trevor Boyd Smith


People also ask

How do I install two Python versions on Ubuntu?

Install that version using "make install". Install all other versions using "make altinstall". For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being the primary version, you would execute "make install" in your 2.6 build directory and "make altinstall" in the others.

Can you have two versions of Python installed Linux?

It can install multiple Python versions, specify the version that's used system-wide, and specify the version that's used in specific directories. It can also create and manage virtual environments using specific versions.

Can I have two versions of Python installed?

If you wish to use multiple versions of Python on a single machine, then pyenv is a commonly used tool to install and switch between versions. This is not to be confused with the previously mentioned depreciated pyvenv script. It does not come bundled with Python and must be installed separately.


2 Answers

When you install from source, by default, the installation goes in /usr/local -- the executable in particular becomes /usr/local/bin/pythonX.Y with a symlink to it that's named /usr/local/python. Ubuntu's own installation is in /usr/ (e.g., /usr/bin/python), so the new installation won't overwrite it. Take care that the PATH environment variable doesn't have /usr/local/bin before /usr/bin, or else simple mentions of python would execute the new one, not the old one.

like image 81
Alex Martelli Avatar answered Oct 14 '22 20:10

Alex Martelli


I'm just going to assume that by "newer version" you mean "released version that is newer than the default version in Ubuntu". That means python 3.1, which is in the repositories.

sudo apt-get install python3

Different python versions in the Ubuntu repositories can coexist with one another just fine. If you're on a version of Ubuntu older than Lucid, you'll have to upgrade your OS or enable the universe repository in order for python3 to show up in your package manager.

If you mean python 2.7, you should be aware that it hasn't been released yet.

like image 20
ʇsәɹoɈ Avatar answered Oct 14 '22 20:10

ʇsәɹoɈ