I had a system crash and now my Ubuntu runs into low-graphics mode. All the fixes require running commands with sudo. When I try this I get sudo: command not found. When I try logging in with su.
There are a few question on the site that seem related to my problem but I could not find a solution in any of them.
My operating system is Ubuntu 12.04. I have mvn
installed in /tools/noarch/apache-maven-3.1.1
and I have added the following lines at the end of my /etc/profile
:
After that I execute source /etc/profile
.
Now my problem is: when I run mvn --version
the command succeeds and mvn
executable is found, while if I execute: sudo mvn --version
I get the output: sudo: mvn: command not found
. I know that PATH
may be different when I execute a command with sudo
and that is why I tried this:
Another thing I tried is to execute sudo su -
and then type mvn --version
. In this case mvn
is successfully found and the command succeeds. What is going on here?
$PATH
is evaluated by your shell, so your check doesn't work as you expect it to.
/etc/sudoers
is configured to replace your PATH
with a default one.
sudo
does not load a login shell environment before executing the command, so the default PATH
from /etc/sudoers
is used. su -
does open a login shell, which involves loading /etc/profile
. See man bash
, section INVOCATION.
Just remove the PATH
reset in /etc/sudoers
. It's likely a rule called secure_path
.
In CentOS you can add PATH
to the Defaults env_keep
section:
Elaborating on @opyate's answer, I am using the following shell script (which may be named mysudo
, for example):
-E
tells sudo
to preserve the environment.env 'PATH=$PATH'
is expanded outside the sudo
call, making the external PATH
available inside the sudo
too (this is required in addition to the -E
as the PATH
usually receives special treatment in addition to the treatment the entire environment receives).'$@'
passes the arguments our script receives to the sudo
line.Save the script in a file in a directory in the PATH
, give it +x
permissions, et voilà.
Since the current answers are a little vague, the specific setting in /etc/sudoers
changing your path is secure_path
:
You can modify it it with sudo visudo
, or better yet, add the directories you need:
I had the same problem when I first installed Maven. The problem got solved after I added the two lines,
to four files:
and for the current user (mehran
is my Ubuntu username):
You must modify root's PATH variable exactly like you did for yourself, i.e. by adding those two lines in sudo's profile, which is located in /root/.bashrc, then source it.
MariusMatutiaeMariusMatutiaeWhen I have made changes on the DNS host.
How do I get the clients (servers) to update/flush their DNS cache, so they see the change right away?
SandraSandraYou can restart BIND on Ubuntu using sudo rndc reload
, on Centos I believe you have to /etc/init.d/bind restart
.
You can also execute /etc/init.d/networking restart
to flush the DNS/networking for local desktops running Ubuntu.
I have found that a simple restart does not always clear the cache.The other way of doing it, would be to use the nscd command and invalidate the hosts cache.
Then you don't even need to restart the caching service.
Depending on you distribution, the clients may not cache by default. For Ubuntu or CentOS, try this command:sudo /etc/init.d/nscd status
...to see if the caching demon is running. If it is, then your client is caching DNS and you can flush it with this:sudo /etc/init.d/nscd restart
if NSCD is not running then there is nothing to flush on the client and you need to:1. make sure the old entry is not in the /etc/hosts file2. make sure the DNS change has already propagated to any DNS slaves (check the resolv.conf for where it is resolving to)