Ubuntu 14.04 LTS (Trusty Tahr) ships with Python 2.7.6 by default, which lacks several important security fixes present in Python 2.7.9. The latter introduced critical SSL/TLS improvements including:
- Hostname verification in HTTPS connections
- Support for Server Name Indication (SNI)
- Improved certificate validation
There are two main approaches to get Python 2.7.9 on Ubuntu 14.04:
Method 1: Using Dead Snakes PPA
The most reliable way is through the Deadsnakes PPA which maintains newer Python versions for older Ubuntu releases:
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python2.7=2.7.9-1+trusty1
Method 2: Compiling from Source
For environments where PPAs aren't allowed, you can build from source:
wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
tar xzf Python-2.7.9.tgz
cd Python-2.7.9
./configure --prefix=/usr/local --enable-optimizations
make
sudo make altinstall
After installation, verify the Python version and SSL support:
python2.7 -c "import ssl; print(ssl.OPENSSL_VERSION)"
python2.7 -V
You might need to reinstall pip and other tools:
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
sudo python2.7 get-pip.py
sudo pip2.7 install --upgrade setuptools
Common problems and their solutions:
- Broken dependencies: Run
sudo apt-get -f install
- Conflicting packages: Use
update-alternatives
to manage multiple Python versions - SSL module missing: Ensure libssl-dev is installed before compiling
Remember that Ubuntu's system tools rely on Python 2.7.6. To avoid breaking system functionality:
- Never remove Python 2.7.6 completely
- Use virtual environments for projects requiring 2.7.9
- Consider using pyenv for version management
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncurses5-dev libncursesw5-dev xz-utils tk-dev
curl https://pyenv.run | bash
pyenv install 2.7.9
pyenv global 2.7.9
Ubuntu 14.04 LTS (Trusty Tahr) ships with Python 2.7.6 by default, but version 2.7.9 introduced critical security improvements - most notably the ssl
module enhancements and HTTPS verification capabilities. Many legacy systems still require Python 2.7, making this upgrade path valuable for security-conscious developers.
First attempt using Ubuntu's package manager:
sudo apt-get update sudo apt-get install python2.7=2.7.9*
If this fails (likely on 14.04), you'll see output indicating the version isn't available in standard repositories.
When package managers don't have the version you need, source compilation is reliable:
wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz tar xvf Python-2.7.9.tgz cd Python-2.7.9 ./configure --prefix=/usr/local --enable-optimizations make sudo make altinstall
The altinstall
prevents overwriting the system Python. Verify with:
/usr/local/bin/python2.7 --version
For project-specific usage without affecting system Python:
sudo apt-get install python-virtualenv virtualenv -p /usr/local/bin/python2.7 myproject source myproject/bin/activate
Common issues you might encounter:
sudo apt-get install build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev
After installation, verify SSL support:
python -c "import ssl; print(ssl.OPENSSL_VERSION)"
Should show OpenSSL 1.0.1 or later (included in Python 2.7.9+).
Test critical functionality with:
python -c "import urllib2; print(urllib2.urlopen('https://www.python.org').read(100))"