Results 1 to 4 of 4

Thread: Changing root's $PATH variable

  1. #1
    Join Date
    Jun 2007
    Beans
    129

    Changing root's $PATH variable

    Hi:

    I have a program that I wanted to add to the $PATH environment variable. Now, I've done it successfully for regular users, but unfortunately when I prepend sudo in front of it (to run it as root), I get
    Code:
    "sudo: myapp: command not found"
    where myapp is the name of the program. I have read around and tried various solutions, but nothing seems to work:

    1. Adding "export PATH=$PATH:path_to_myapp" to /root/.bashrc
    2. Adding "export PATH=$PATH:path_to_myapp" to /root/bash_profile
    3. Appending path_to_myapp to both ENV_SUPATH and ENV_PATH in /etc/login.defs


    I tried each solution in isolation (i.e., I tried approach #1, then reversed my changes and tried approach #2, etc.), and also logged-out/logged-back-in after each approach.

    I know they don't work because when I type
    Code:
    sudo env
    the $PATH variable does not reflect my changes.

    I would appreciate any help on this matter.

    Cheers,
    LK
    Last edited by LordKelvan; November 3rd, 2008 at 04:02 AM.

  2. #2
    Join Date
    Oct 2005
    Location
    Jacksonville, FL
    Beans
    29,420

    Re: Changing root's $PATH variable

    After you add it to /root/.bashrc, you need to rehash it with

    Code:
    sudo source /root/.bashrc
    In the world of Linux, who needs Windows and Gates...

    Got most of my golden beans at an auction on eBay (with a couple of free drinks).

  3. #3
    Join Date
    Jun 2007
    Beans
    129

    Re: Changing root's $PATH variable

    As I pointed out in my original post, I logged out, then logged back in after adding it to /root/.bashrc. Is this not sufficient?

    And I assume you are also saying that adding "export PATH=$PATH:path_to_myapp" to /root/.bashrc is the proper way to accomplish what I want?

    ************EDIT*******************

    I tried the following steps again:

    1) Added the line "export PATH=$PATH:path_to_myapp" to /root/.bashrc.
    2) Logged out
    3) Logged back in

    And still it fails with "command not found" when I prepend sudo.
    Last edited by LordKelvan; November 17th, 2008 at 04:40 AM.

  4. #4
    Join Date
    Jun 2007
    Beans
    129

    Re: Changing root's $PATH variable

    Hi:

    I've solved the problem - the solution is here http://stackoverflow.com/questions/2...anges-path-why.

    Basically, it appears there is a bug with sudo. In Ubuntu, sudo is compiled with the flag "--with-secure-path", and the bug prevents you from stopping sudo from resetting $PATH. The solution is to add
    Code:
    alias sudo='sudo env PATH=$PATH'
    to ~/.bashrc.

    If you would like further details, and some other possible solutions, please visit the above link. Although I'm not affiliated with the site, I've increasingly found http://www.stackoverflow.com to be very useful in solving programming/computer-related problems.

    Cheers,
    LK
    Last edited by LordKelvan; November 21st, 2008 at 09:48 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •