Updating Python on Ubuntu system
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay
--
Chapters
00:00 Question
00:42 Accepted answer (Score 83)
05:12 Answer 2 (Score 21)
05:28 Answer 3 (Score 13)
05:48 Answer 4 (Score 5)
06:09 Thank you
--
Full question
https://superuser.com/questions/241865/u...
Accepted answer links:
[Python 2.6]: http://packages.ubuntu.com/maverick/pyth...
[Python 2.7]: http://packages.ubuntu.com/maverick/pyth...
[Python 3.1]: http://packages.ubuntu.com/maverick/pyth...
[humongous]: https://github.com/vinta/awesome-python
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#ubuntu #python #linuxdistributions
#avk47
ACCEPTED ANSWER
Score 84
As others already noted, bare sudo apt-get install package will install latest available version, replacing the older one if needed.
But with some software (among which is Python) the situation is somewhat different. Some major, very- and incompatibly-different versions get their own packages. For instance, Python 2.6, Python 2.7, Python 3.1 all live in separate packages on Ubuntu.
Of particular importance is the fact that one of Ubuntu policies is to extensively use Python for writing end-user software. So in fact, fairly large part of the system is written in Python. At the moment, the code runs on Python 2.6 — so this version is the default upon installation; and the code won't easily run on, say, Python 2.7 — because incompatibilities exist. To switch the system to Python 2.7 there needs to be done a piece of work, consisting of updating and re-testing all the scripts. This can't be done easily; that is, you can't just "switch" your system to Python 2.7 and delete the older version.
But. If you don't care about fancy gears of your system and just need newer Python — see no obstacles. Go and sudo apt-get install python3 and code for 3.x Python bravely; just remember to launch your scripts with python3 and use #!/usr/bin/env python3 shebang line.
Upd: I keep seeing this upvoted; notice that this is a 9-year old answer, things have changed.
What to learn next
From a superuser perspective (not Python developer's), the next things I'd suggest learning to use:
pip/pip3/python3 -m pip— this is thenpmfor Python. Quick tip: trypip3 install --user howdoi(may need toapt install python3-setuptools python3-piponce, before that works). Then for example,howdoi --all compile python3 ubuntu.The
virtualenvtool. It's 100% developer-oriented, but you'll likely need to use it (perhaps underneath a few wrappers, such astox) to work with people's source packages.
Ruby'sbundleror Cabal sandbox may be familiar analogues.The
condatool — which is a totally separate python package repository and installer (think: fork of PyPi).
There's humongous variety of tools in the Python ecosystem in 2020. At the very least, make yourself comfortable with pip before going deeper.
Basic pitfalls
For the brave but unwary, a few classic pitfalls when trying to manually set up a newer CPython on Ubuntu.
Leave
/usralone; you can look but you don't touch. Leave it todpkg, save yourself some confusion. You have the whole/usr/localat your disposal:sudo chown -R `whoami` /usr/local pip3 install --prefix=/usr/local pydfCompiling CPython from source is well-explained on the web; just don't forget your
/usr/localprefix. This is the best way to manually test patches and/or pre-releases (those alpha-, rc- builds) of CPython itself. To wipe built artifacts, you can justrm -rf /usr/local/*; sudo ldconfig.Finding a PPA is decent option too; keep in mind that a PPA is just someone else's private build. Look for credible PPAs with CI/CD running.
ANSWER 2
Score 21
sudo apt-get install python 3.3.3
this is for python(3.3.3) for different version the corresponding version number should be used.
ANSWER 3
Score 5
You're close with thinking of a command like sudo apt-get update (which is an actual command, but doesn't do what you want it to.)
To upgrade Python, and everything else you have installed, just do the command:
sudo apt-get upgrade
ANSWER 4
Score 4
From our sister site: https://askubuntu.com/questions/44122/how-to-upgrade-a-single-package-using-apt-get
Each of these commands updates-by-installing, which should work just fine in many cases, but might not be what you're looking for in a specific case.
If you only want to upgrade a specific package AND only if it is already installed, then use the command:
sudo apt-get install --only-upgrade packagename