How to Install Python 2 on FreeBSD 14

Updated on 10 April, 2025
How to Install Python 2 on FreeBSD 14 header image

Python 2 reached end-of-life in 2020 but remains necessary for running legacy applications. Many older scripts, tools, and frameworks still depend on it, so you may need to install Python 2 on FreeBSD. FreeBSD 14 comes with Python 3 by default, so manual installation is required to enable Python 2 support.

This article explains how to install Python 2 on FreeBSD 14.

Prerequisites

Before you begin:

Compile and Install Python 2 on FreeBSD 14

Follow the steps below to compile and install Python 2 from the source code.

  1. Verify the default Python version.

    console
    $ python --version
    

    Output.

    Python 3.11.11

    The above output confirms that Python 3 is the system's default Python binary.

  2. Python 2 is no longer in FreeBSD's package repositories. Download the Python 2.7 source from the Python releases page.

    console
    $ wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
    
  3. Extract all files from the downloaded tarball.

    console
    $ tar -xvzf Python-2.7.18.tgz
    
  4. Navigate to the extracted directory.

    console
    $ cd Python-2.7.18
    
  5. Run the configuration script with shared library support.

    console
    $ ./configure --with-system-ffi --with-computed-gotos --enable-shared
    
  6. Compile using all CPU cores for faster processing.

    console
    $ make -j$(sysctl -n hw.ncpu)
    
  7. Install Python 2 without overwriting the default Python binary.

    console
    $ sudo make altinstall
    

Test the Python 2 Installation

Follow the steps below to test the Python 2 installation on your FreeBSD server.

  1. Verify the installation.

    console
    $ python2.7 --version
    

    Output:

    Python 2.7.18
  2. Check the default Python binary version.

    console
    $ python --version
    

    Output:

    Python 3.11.11

    You can see that both versions are now available on your instance.

  3. Create a symbolic link to allow the python2 command to run the python2.7 binary.

    console
    $ sudo ln -s /usr/local/bin/python2.7 /usr/local/bin/python2
    

Compile and Install PIP for Python 2

Pip is the standard Python package manager for managing Python packages and dependencies in your projects. Python 2 doesn't include Pip by default, so you'll install it manually.

  1. Download the Pip installation script for Python 2.

    console
    $ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
    
  2. Install Pip for Python 2.7.

    console
    $ sudo python2.7 get-pip.py
    
  3. Verify the Pip installation.

    console
    $ pip2.7 --version
    

    Output.

    pip 20.3.4 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)

Test and Use Python 2

It's important to verify that everything works as expected after completing the installation. Follow the steps below to test your Python 2 installation.

  1. Launch the Python 2 interpreter.

    console
    $ python2
    
  2. Run the following command to display a Hello World, Greetings from Vultr! message in your terminal.

    python
    >>> print('Hello World, Greetings from Vultr!')
    

    Output.

    Hello World, Greetings from Vultr!
  3. Exit from the Python shell.

    python
    >>> quit()
    
  4. To test Pip, install the Flask Python module using Pip.

    console
    $ pip2.7 install flask
    

    Output:

    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python version since Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
    Name: Flask
    Version: 1.1.4
    Summary: A simple framework for building complex web applications.
    Home-page: https://palletsprojects.com/p/flask/
    Author: Armin Ronacher
    Author-email: armin.ronacher@active-4.com
    License: BSD-3-Clause
    Location: /home/jsah/.local/lib/python2.7/site-packages
    Requires: click, Jinja2, Werkzeug, itsdangerous
    Required-by:

Conclusion

You now have a fully functional Python 2.7 binary on your FreeBSD 14 instance that coexists with the system's default Python 3 binary. This setup allows you to run legacy applications while maintaining modern Python support. For additional guidance on working with legacy codebases, refer to the Python 2.7 documentation.

Comments

No comments yet.