Overview
This article explains how to install a custom version of Python 3 on your DreamHost server.
Background
Python 3 is installed by default on Shared, VPS, and Dedicated Servers. However, if you wish to use a different version, you can install it locally under your shell user.
To run the commands in this article, you must log in to your server via SSH with your shell user. View the following articles for more information:
Installing zlib (Shared servers only)
The zlib package is not available by default on Shared web servers. To install a custom version of Python 3, you must first install the zlib library. You will then use it when configuring your Python installation.
The instructions below install version 1.3.1. Make sure to change this to your chosen version in the commands below.
- Log in to your server via SSH.
-
Run the following commands to create a tmp directory in your user's home directory:
[server]$ cd ~ [server]$ mkdir tmp [server]$ cd tmp
- Visit the zlib website. Under the current release section, right-click the first US (zlib.net) link and select Copy Link Address.
-
In your terminal, type in wget and paste the zlib link. Then, run the following command:
[server]$ wget https://zlib.net/zlib-1.3.1.tar.gz
The wget command may fail with the following error:
ERROR 415: Unsupported Media Type.
If you see this, try downloading the file manually from the website by clicking the link. Then upload the file via FTP to your web server into the ~/tmp directory.
-
Decompress the file:
[server]$ tar xzvf zlib-1.3.1.tar.gz
-
Change into the zlib directory and configure the library:
[server]$ cd zlib-1.3.1 [server]$ ./configure --prefix=$HOME/local [server]$ make && make install
This installs libz.a, libz.so, and headers into $HOME/local/lib and $HOME/local/include.
Installing Python 3
The following installs a custom version of Python 3.
-
Visit python.org and choose the version you wish to install.
The instructions below install version 3.14.0. Make sure to change this to your chosen version in the commands below.
- Right-click on the link titled Gzipped source tarball of the version you wish to install. From the pop-up menu, choose Copy Link Address.
-
Log in to your server via SSH and run the following commands one at a time to configure Python:
[server]$ cd ~ [server]$ mkdir tmp [server]$ cd tmp [server]$ wget https://www.python.org/ftp/python/3.14.0/Python-3.14.0.tgz [server]$ tar zxvf Python-3.14.0.tgz [server]$ cd Python-3.14.0
-
Configure using one of the options below, depending on your web server type.
VPS and Dedicated Servers
[server]$ ./configure --prefix=$HOME/opt/python-3.14.0
Shared servers only
This uses your local installation of zlib to configure Python.
[server]$ ./configure --prefix=$HOME/opt/python3.14 \ CPPFLAGS="-I$HOME/local/include" \ LDFLAGS="-L$HOME/local/lib" \ --enable-optimizations
-
Run the make commands to install Python.
Shared servers only
When installing custom versions of Python on a Shared server, you may encounter the following error:
Resource temporarily unavailable
To resolve this issue, set the -j6 flag using the following sed command. This command must be run right after the ./configure step above.
[server]$ sed -i 's/-j0/-j6/g' Makefile*
This edit permits up to six jobs to run concurrently during compilation, optimizing the use of system resources. This modification applies to the following three makefiles:
- Makefile
- Makefile.pre
- Makefile.pre.in
If issues persist after these changes, please reach out to customer support for further assistance.
[server]$ make [server]$ make install
These commands install your local version of Python to /home/username/opt/python-3.14.0.
-
Navigate back to your user's home directory:
[server]$ cd ~
-
View the creating and editing a file via SSH article for instructions on how to edit your existing .bash_profile. To use the new version of Python over the system default, enter the following line to your .bash_profile:
export PATH=$HOME/opt/python-3.14.0/bin:$PATH -
Save and close the file, and then return to your shell. Run the following command to update this file:
[server]$ . ~/.bash_profile
-
Check which version of Python you're now using by entering the following command:
[server]$ python3 --version Python 3.14.0
If there is no response, then the newly downloaded copy is not being used. Most often, this is due to the .bash_profile not being updated correctly. Try logging out and back in again. If necessary, repeat the steps above.
Updating to a newer version
There is no simple option to automatically update your custom Python installation to a newer version. You would follow the same steps above to download, install, and activate the version of your choice.