How to install alternative version of Python beside distro supplied?

10,178

Solution 1

Download one of the source tarballs on this page.

Then, unpack it, cd into the directory, and follow the directions in section 2.2 of the python online manual.

If you want it to install to, for example, /usr/bin instead of the default (/usr/local/bin in ubuntu/debian), then instead of ./configure, type ./configure --prefix=/usr when told to use it in the guide.

For in your $HOME/bin directory, use --prefix=$HOME.

If it doesn't exist, add $HOME/bin to your $PATH like this:

$ export PATH=$HOME/bin:$PATH

This may already be in your .bashrc in ubuntu, and others. If it is, when you next log in, $HOME/bin will be added to your $PATH automatically.

Solution 2

Use ALTINSTALL for alternative installation to not replace your default Python3.

tar zxvf Python-2.6.5.tgz
cd Python-2.6.5
./configure
make
make altinstall

For further info check the relevant python documentation. Take note if the instructions are for the version you are about to install.

Solution 3

For that, I believe you would need to compile from source and use the --prefix option.

  1. Download Python
  2. Untar tar -xvf python*.tar.bz2
  3. CD to the directory: cd python
  4. Compile/install: ./configure --prefix=/home/$(whoami)/desired_folder && make && make install
  5. Add it to your path to be able to invoke it.
Share:
10,178

Related videos on Youtube

Xandrmoro
Author by

Xandrmoro

I could tell you about myself but I don't think it would tell you anything about myself. I think it's best for now if I just let my questions and answers speak for me.

Updated on September 18, 2022

Comments

  • Xandrmoro
    Xandrmoro over 1 year

    Is there any official way to install a specific version of Python, at least 2.6, manually into my chosen directory? I do not necessarily have root privileges on the host that I am installing to.

    After I complete the Python installation, I will need to install pip for it. It is essential to me that the system supplied Python (2.4.3 packaged with CentOS 5) is completely ignored for all my purposes. In essence, my entire Python and pip installation procedure has to behave as if no previous version of python is installed on the system.

    Do I compile it from source, or can I have some form of package I can just extract somewhere and run Python from? I prefer the latter, as I try to avoid installing development software stack on the host (it is a server, not a dev workstation).

  • Xandrmoro
    Xandrmoro over 10 years
    That's the thing - I don't have python on the host, and I am in no position to use package manager to install it. In fact I don't even have development tools to build it from source, but that restriction is more relaxed - I can install these [dev] tools. Anyhow, I will have to build and install python first, then pip, then virtualenv. Thanks for the instructions on virtualenv usage though.
  • Wyatt Ward
    Wyatt Ward about 10 years
    I did not know about virtualenv. it looks neat. But how is this different from a chroot?
  • Alex Forbes
    Alex Forbes about 10 years
    A chroot prevents the application from acessing anything outside its jail. virtualenv does not do this; it only isolates your python code from the system's python binaries and modules. Thus you can log to /var/log, call external binaries from /usr/bin and do anything a non-chrooted app can do.
  • Xandrmoro
    Xandrmoro over 7 years
    I think he was asking for principal difference, in context of isolating Python. To that end, preventing application from accessing anything outside its "jail" is irrelevant. Even a chrooted program sees /var/log, /usr/bin, etc, it's just that the actual data that is available addressing /var/log and /usr/bin in this case, may be different -- it doesn't have to be the same /var/log and /usr/bin. You change the root, but you can't get rid of it. Jailing is a loose term which can describe something that can be done with chroot, but the two have a bit different scope.
  • Anaksunaman
    Anaksunaman about 6 years
    Welcome to Super User! This seems like a good answer but for anyone unfamiliar with Linux, these commands might be a bit opaque. You may want to consider adding a brief explanation of the steps you're taking and why in addition to the commands themselves.