This article is outdated and may not work correctly for current operating systems or software.
Python is an open-source language written by Guido Von Rossum and actively maintained by not only the Python core developers, but also the community. In this article, we will learn how to download, build from source, and install the Python programming language.
Before installing any new software on your server, be sure to update your repository list and upgrade so as to stay as up-to-date on the current features and security that roll-out during each software's lifecycle. We can do this by executing the following commands.
sudo apt-get update sudo apt-get upgrade
Be sure to follow the on-screen prompts in case anything can be removed after having been deprecated, or if further action is required. This is essential to the success of your Python building and installation process.
We'll need a few packages in order to actually build Python from source.
sudo apt-get install build-essential libssl-dev zlib1g-dev libncurses5-dev libreadline-dev libgdbm-dev libdb5.3-dev libbz2-dev liblzma-dev libsqlite3-dev libffi-dev tcl-dev tk tk-dev
Now, we must download the source. Because it comes compressed, we'll have to extract it before we can do anything else with it.
Start by executing the following command to begin downloading the source from the Python FTP server.
cd ~ && wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
Now decompress the file and enter the directory.
tar xf Python-3.6.0.tar.xz && cd Python-3.6.0
Now we execute
./configure --enable-optimizations in order to configure the
make files that will be used to build.
After having successfully configured, we can issue the following command to begin building.
Note: with the command above you may need to change the number in
-j2to something more appropriate. If your server has a dual-core processor, this is as good as you can get. Otherwise, if your server has more that two cores, you can adjust the command accordingly. You may also remove
-j2totally to build on only one core, however, this may take quite a while (upwards of 2 or more hours).
After completing the build process, you may want to install the freshly built Python 3.6.
sudo make altinstall
install in an effort to avoid interfering with any pre-installed version that your server's operating system may rely on.
Once you've executed that last command, you should have a custom built Python 3.6 installation. You can check that you have successfully installed it by issuing
python3.6. If your console returns something along the lines of the following, then you're done.
example@example:~$ python3.6 Python 3.6.0 (default, Aug 14 2017, 03:53:56) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
You may also find Python language documentation on the official Python website.