To install Python 3.8 on Ubuntu version 23
Open your terminal and run these commands:
Install build dependencies
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm \
libncurses5-dev libncursesw5-dev xz-utils tk-dev \
libffi-dev liblzma-dev python3-openssl git
Download and extract Python 3.8 source code
mkdir ~/python38
cd ~/python38
wget https://www.python.org/ftp/python/3.8.16/Python-3.8.16.tgz
tar -xf Python-3.8.16.tgz
cd Python-3.8.16
Configure the build
./configure --enable-optimizations
Compile the source code
make -j$(nproc)
Install Python
sudo make install
Verify the installation
python3.8 --version
To create a virtual environment specify the Python version.
Example:
python3.8 -m venv venv
linux - How to install python 3.8 directly in /usr/bin? - Stack Overflow
How to install Python 3.8
How to Install Python 3.8 on LinuxMint
How to install python 3.8.12 on /usr/bin/python? - Stack Overflow
Videos
To install Python 3.8 on Ubuntu version 23
Open your terminal and run these commands:
Install build dependencies
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm \
libncurses5-dev libncursesw5-dev xz-utils tk-dev \
libffi-dev liblzma-dev python3-openssl git
Download and extract Python 3.8 source code
mkdir ~/python38
cd ~/python38
wget https://www.python.org/ftp/python/3.8.16/Python-3.8.16.tgz
tar -xf Python-3.8.16.tgz
cd Python-3.8.16
Configure the build
./configure --enable-optimizations
Compile the source code
make -j$(nproc)
Install Python
sudo make install
Verify the installation
python3.8 --version
To create a virtual environment specify the Python version.
Example:
python3.8 -m venv venv
Assuming you need this simply for development reasons, there's no reason to install it, but rather build it only.
Follow the steps from @GODFREY but skip the install altogether - which most probably will screw up your system.
After make -j$(nproc) you get a python binary in the directory which you can test
./python --version
# => Python 3.10.14
Now in your python project you can use virtualenv directly to use the binary
# Assuming the source is in ~/Python-3.10.14
virtualenv -p ~/Python-3.10.14/python .venv
source .venv/bin/activate
python --version
# => Python 3.10.14
By default, CPython install compiled python binary in /usr/local/bin/python. (source code: https://github.com/python/cpython/blob/main/configure#L571) You may specify the prefix mannually as configure --prefix=/usr.
You need to set symlinks such as
$ sudo ln -sfn /usr/local/bin/python3.8 /usr/bin/python3.8
$ sudo ln -sfn /usr/local/bin/pip3.8 /usr/bin/pip3.8
The above works great in CentOS7 after installing Python3.8 as noted above.
This post is community wiki so as to not claim the credit of @Kulfy's comment. This procedure worked on Ubuntu 18.04.
DON'T EVER CHANGE DEFAULT PYTHON!!! It may cause your system to break and some applications won't even run. It's far far far better to invoke python3.8 using
python3.8command
When installing python3.8, do the following
$ sudo apt-get install python3.8 python3.8-dev python3.8-distutils python3.8-venv
For most people this will be acceptable as they will be using a virtual environment for development. Construct a virtual environment and activate it as you usually would. This will leave you in a terminal where python resolves to python3.8:
$ python3.8 -m venv dev3.8/
$ source dev3.8/bin/activate
(dev3.8) $ which python
...dev3.8/bin/python
(dev3.8) $ python --version
Python 3.8.0
Neglecting to install python3.8-venv will result in an unhelpful error, that suggests you should install python-venv which resolves to python3.6-venv:
$ python3.8 -m venv dev3.8/
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ... (trimmed for formatting)
Step 1: Install the latest version of python. Currently, 3.8 is the latest
sudo apt install python3.8
Step 2: Add Python 3.6 & Python 3.8 to update-alternatives
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6.9
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8.1
Step 3: Update Python 3 to point to Python 3.7
By default, Python 3.6 is pointed to Python 3. So, we run python3 it will execute as python3.6 but we want to execute this as python3.8
sudo update-alternatives --config python3
You should get a similar output. Now type 2 and hit enter for Python 3.
Step 4: Test the version of python
Finally test the current version of python by typing
python3 -V
At the writing time of this article Python latest stable version 3.8 series is available to install. This article will help you to install Python 3.8 on LinuxMint operating system. You can visit here to read more about Python releases.
Step 1 β Prerequisites
Use the following command to install prerequisites for Python before installing it.
sudo apt-get install build-essential checkinstall sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \ libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
Step 2 β Download Python 3.8
Download Python from the python official site.
Step 3 β Install Python 3.8
After download extract the .tar.xz file. Then inside the Python-3.8.0 folder open terminal. Use below set of commands to install Python 3.8
./configure make make test sudo make install
All Done! This will install Python as ``python3``. Open the terminal and see yourself!
That article is outdated, most likely written at a time where Python 3.8 was not yet available on the stable Ubuntu repositories.
You can install the latest Python available with just apt install python3 (3.9 at the moment).
If you really want 3.8, I suggest you take a look at the deadsnakes PPA. It contains an archive of all Python packages for Ubuntu, and also newer versions that haven't hit Ubuntu stable yet (like 3.10).
You can add this PPA and install Python 3.8 with just three commands:
Copyadd-apt-repository ppa:deadsnakes/ppa
apt update
apt install python3.8
Regarding your other two bullet points:
- Yesn't. The thing is that, by default,
/usr/binis included in yourPATHenvironment variable, which what enables you to just typepython ...instead of providing the absolute path for the binary. It is also expected by some scripts, I suppose. - You could, and you could also symlink it. The reason why it wasn't put there already is because the article used
altinstall, which prevents exactly that. It is way more preferable that you install stuff through your package manager, however.
You can do it using snap:
Copysnap install python38
While we can use pip directly as a Python module (the recommended way):
python -m pip --version
This is how I installed it (so it can be called directly):
Firstly, make sure that command pip is available and it isn't being used by pip for Python 2.7
sudo apt remove python-pip
Now if you write pip in the Terminal, you'll get that nothing is installed there:
pip --version
Output:
Command 'pip' not found, but can be installed with:
sudo apt install python-pip
Install python3.8 and setup up correct version on python command using update-alternatives (as done in the question).
Make sure, you have python3-pip installed:
(This won't work without python3-pip. Although this will install pip 9.0.1 from python 3.6, we'll need it.)
sudo apt install python3-pip
This will install pip 9.0.1 as pip3:
pip3 --version
Output:
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
Now, to install pip for Python 3.8, I used pip by calling it as a python module (ironic!):
python -m pip install pip
Output:
Collecting pip
Downloading https://files.pythonhosted.org/packages/36/74/38c2410d688ac7b48afa07d413674afc1f903c1c1f854de51dc8eb2367a5/pip-20.2-py2.py3-none-any.whl (1.5MB)
100% |ββββββββββββββββββββββββββββββββ| 1.5MB 288kB/s
Installing collected packages: pip
Successfully installed pip-20.2
It looks like, when I called pip (which was installed for Python 3.6, BTW) as a module of Python 3.8, and installed pip, it actually worked.
Now, make sure your ~/.local/bin directory is set in PATH environment variable:
Open ~/.bashrc using your favourite editor (if you're using zsh, replace .bashrc with .zshrc)
nano ~/.bashrc
And paste the following at the end of the file
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
Finally, source your .bashrc (or restart the Terminal window):
source ~/.bashrc
Now if you try running pip directly it'll give you the correct version:
pip --version
Output:
pip 20.2 from /home/qumber/.local/lib/python3.8/site-packages/pip (python 3.8)
Sweet!
As suggested in official documentation you can try with get-pip.py.
wget https://bootstrap.pypa.io/get-pip.py
python3.8 get-pip.py
This will install pip as pip3.8.
Make sure you have python3.8-distutils installed to avoid below error
"No module named 'distutils.cmd'" error.
You can install distutils using:
sudo apt install python3.8-distutils
Amazon has it's own Linux with extras, the command is:
sudo amazon-linux-extras install python3.8
taken from https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install-linux.html but after installing 3.7 from there, there is the above update command appearing during the install telling how to upgrade. Ahh the convolution of hosted virtual machines, still easier than trying to get a console command line login on any other Linux on AWS.
It does rebuild the python to 3.8, cleaning up files from 3.7, so boom a clean build of 3.8 thanks to Amazon.
All that being said, the default "python" will still be 2.7 as there is no backward compatibility, and many think getting rid of 2.7 will cause problems.
So what NOT TO DO NEXT as we are done is:
sudo rm /usr/bin/python (which is only a link to /usr/bin/python2.7)
sudo ln -s /usr/bin/python3.8 /usr/bin/python
but usually peeps simply type python3.8 to specifically run the new version.
These answers are now out of date as of Amazon Linux 2023. Amazon Linux 2023 FAQ
Q: Does AL2023 have Amazon-Linux-Extras like AL2?
A: No, AL2023 does not have extras. For higher-level software packages like language runtimes, we will use the quarterly release where we will add major/minor updates to packages as separate namespaced packages in addition to the default package provided in the repository. For example, default Python version in Amazon Linux 2023 may be 3.8, but we will add Python 3.9 (python39) as a separate namespaced package whenever it is made available. These additional packages will closely follow their upstream release cadence and support model and their support policies can be accessed by the package manager for compliance and security use cases. Default packages will continue to be supported throughout the life of AL2023.
Python is installed by default as python3 exact version is managed by Amazon. It is possible to pick a different version, but I have not found the instructions, since the currently install 3.9 works for my needs.
python3 --version
Python 3.9.16
python3x --version
always generated
-bash: python3x: command not found
regardless of choice of x