How to set 'python2.x' / 'python3.x' to default 'python' in ubuntu ?

Hello pythonic monks,

If you have multiple Python versions installed on your Ubuntu machine and facing difficulty in typing the correct version number of python on running each command, then this article is for you.

Here I will show how you can set python2.x / python3.x to just python in your machine.


Step 1: Open terminal and type 

gedit ~/.bashrc  

and hit Enter.

Step 2: The .bashrc file will open in gedit editor. Go to the last line, type 

alias python=python3.x  

and save the file. 

Also, don't forget to change python3.x to the version you want to set as python default.

Step 3: In the terminal, run

source ~/.bashrc

Step 4: Now when you will run 

python -V

in your terminal, you will see that it will output the python3.x version you have mentioned above.


You are all set now. You can now use 'python' for 'python3.x' version.

Thanks for reading. Happy coding :)

Buy Me a Coffee - https://www.buymeacoffee.com/agautam

Comments