Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 8
    I like this answer best since it avoids need to change settings globally (i.e. preserves principle of least privilege) Commented Mar 11, 2015 at 0:31
  • 7
    sudo "PATH=$PATH" godi_console did not work in CentOs7 by the way. Needed the env Commented Jan 25, 2018 at 6:29
  • 2
    @StéphaneChazelas Does sudo "PATH=$PATH" godi_console ever really work? sudo accepts VAR=value arguments, affecting the environment of the command it runs, but unlike in env or bash, sudo doesn't seem to let this affect how it looks up the command. I only tested this (recently) on Ubuntu 16.04. But I tried adding the exempt_group option to sudoers (just for testing--I don't consider this a solution!) and the results were illuminating. Commands of the form PATH="$PATH" sudo some-command started working, but those of the form sudo PATH="$PATH" some-command still did not. Commented Apr 13, 2018 at 11:32
  • 2
    @ballsatballsdotballs. As that alias should only affect your interactive shells, that should be relatively harmless. Commented Apr 15, 2018 at 13:43
  • 5
    I just create an alias called psudo for these types of cases, where: alias psudo="sudo env \"PATH=$PATH\"". Then my normal sudo use is unaffected. Commented May 18, 2018 at 18:38