0

I understand sudo doesn't run a command as the current user, but I don't understand why the two following commands produce differing outputs:

Case 1:

user@.../folder$ sudo python
Python 2.7.17 (default, Nov  7 2019, 10:07:09)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Case 2:

user@.../folder$ sudo su
(base) root@.../folder# python
Python 3.7.6 (default, Jan  8 2020, 19:59:22)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
Recessive
  • 107
  • 5
  • [This answer](https://superuser.com/a/771523/432690) under the linked duplicate analyzes `$PATH` among other things. Your `$PATH`s may vary but the point is `sudo` and `su` use different values. – Kamil Maciorowski Apr 02 '20 at 09:10

1 Answers1

0

Your normal user has a different shell environment than root. Your first command:

sudo python

is your regular environment.

user@.../folder$ sudo su
(base) root@.../folder# python

Is your root user environment. Try executing the command env in both environments and you should see plenty of differences. The different python version is probably due to a difference in the $PATH variable. You can see which python you're using with type -a python

HoD
  • 3,277
  • 15
  • 19