In this article, we upgrade to python 3.8
and configure it as the default version of python.
Out of the box default python version for Ubuntu 18.04/10 is python 3.6
and for Ubuntu 19.04/10 is Python 3.7
. As now, Python 3.8.1
is the lastest stable version released on Dec 18, 2019. So it would be better to upgrade last major version.
My Ubuntu version is 18 LTS, however for 19.{04, 10} replace below all python3.6
with python3.7
and run so.
OK, lets start:
Step 0: Check the current python version
Rrun below command to test the current version installed of python.
<span>$ </span>python3 <span>--version</span><span>$ </span>python3 <span>--version</span>$ python3 --version
Enter fullscreen mode Exit fullscreen mode
Output will be like:
python 3.6.8python 3.6.8python 3.6.8
Enter fullscreen mode Exit fullscreen mode
Step 1: Install python3.8
Install python by typing:
<span>$ </span><span>sudo </span>apt update <span>-y</span><span>$ </span><span>sudo </span>apt <span>install </span>python3.8<span>$ </span><span>sudo </span>apt update <span>-y</span> <span>$ </span><span>sudo </span>apt <span>install </span>python3.8$ sudo apt update -y $ sudo apt install python3.8
Enter fullscreen mode Exit fullscreen mode
Step 2: Add python 3.6 & python 3.8 to update-alternatives
<span>$ </span><span>sudo </span>update-alternatives <span>--install</span> /usr/bin/python3 python3 /usr/bin/python3.6 1<span>$ </span><span>sudo </span>update-alternatives <span>--install</span> /usr/bin/python3 python3 /usr/bin/python3.8 2<span>$ </span><span>sudo </span>update-alternatives <span>--install</span> /usr/bin/python3 python3 /usr/bin/python3.6 1 <span>$ </span><span>sudo </span>update-alternatives <span>--install</span> /usr/bin/python3 python3 /usr/bin/python3.8 2$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 $ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
Enter fullscreen mode Exit fullscreen mode
Step 3: Update python 3 to point to python 3.8
By default, Python 3.6
is pointed to Python 3
. That means when we run python3
it will execute as python 3.6
binary but we want to execute this as python 3.8
.
Type this command to configure python3:
<span>$ </span><span>sudo </span>update-alternatives <span>--config</span> python3<span>$ </span><span>sudo </span>update-alternatives <span>--config</span> python3$ sudo update-alternatives --config python3
Enter fullscreen mode Exit fullscreen mode
user@ubuntu1804:~<span>$ </span><span>sudo </span>update-alternatives <span>--config</span> python3There are 2 choices <span>for </span>the alternative python3 <span>(</span>providing /usr/bin/python3<span>)</span><span>.</span>Selection Path Priority Status<span>------------------------------------------------------------</span><span>*</span> 0 /usr/bin/python3.6 1 auto mode1 /usr/bin/python3.6 1 manual mode2 /usr/bin/python3.8 2 manual modePress <enter> to keep the current choice[<span>*</span><span>]</span>, or <span>type </span>selection number:user@ubuntu1804:~<span>$ </span><span>sudo </span>update-alternatives <span>--config</span> python3 There are 2 choices <span>for </span>the alternative python3 <span>(</span>providing /usr/bin/python3<span>)</span><span>.</span> Selection Path Priority Status <span>------------------------------------------------------------</span> <span>*</span> 0 /usr/bin/python3.6 1 auto mode 1 /usr/bin/python3.6 1 manual mode 2 /usr/bin/python3.8 2 manual mode Press <enter> to keep the current choice[<span>*</span><span>]</span>, or <span>type </span>selection number:user@ubuntu1804:~$ sudo update-alternatives --config python3 There are 2 choices for the alternative python3 (providing /usr/bin/python3). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/python3.6 1 auto mode 1 /usr/bin/python3.6 1 manual mode 2 /usr/bin/python3.8 2 manual mode Press <enter> to keep the current choice[*], or type selection number:
Enter fullscreen mode Exit fullscreen mode
You should get the above output. Now type 2 and hit enter for Python 3.8
. Remember the selection number may differ so choose the selection number which is for Python 3.8
.
Alternative update python 3 to point to python3.8
/usr/bin/python3
is just a symlink
. Delete it and make a new symlink
to python3.8
:
<span>$ </span><span>sudo rm</span> /usr/bin/python3<span>$ </span><span>sudo ln</span> <span>-s</span> python3.8 /usr/bin/python3<span>$ </span><span>sudo rm</span> /usr/bin/python3 <span>$ </span><span>sudo ln</span> <span>-s</span> python3.8 /usr/bin/python3$ sudo rm /usr/bin/python3 $ sudo ln -s python3.8 /usr/bin/python3
Enter fullscreen mode Exit fullscreen mode
Step 4: Test the new version of python3
<span>$ </span>python3 <span>-V</span>python 3.8.0<span>$ </span>python3 <span>-V</span> python 3.8.0$ python3 -V python 3.8.0
Enter fullscreen mode Exit fullscreen mode
All done!
暂无评论内容