Sudo Command Not Found
Apr 11, 2013 To fix the error sudo: add-apt-repository: command not found is quite simple. I got this error while I was trying to add a PPA at school, on a Ubuntu 12.04 LTS Server. Nov 6, 2018 - Hello I have an issue when I try to deploy my project with Envoyer. Our host server has no sudo command and I cannot install it with apt-get. Problem: apt-get-repository Command is Missing I was trying to install the latest version of git from the Ubuntu Git Maintainers Team and I needed to add a Personal Package Archive (PPA) to the Software Sources.
The problem
The CKAN installation documentation shows you how to list the installed PostgreSQL databases.
The command looks like this:
When I try that in my shell, I get an error:
The workaround
Daniel2d2art on the CentOS forum worked around the problem by fully qualifying the path to psql.
My psql lives in the directory /usr/pgsql-9.2/bin
, so my workaround now looks like this:
When I try that in my shell, it works:
How do I fix it properly?
I shouldn't have to fully qualify the path, right?
The postgres user already has psql in its path:
How do I fix this properly?
2 Answers
Why sudo ignores your path
sudo doesn't use your user's path or the postgres user's path. sudo has its own path, defined by the the secure_path
variable in the file /etc/sudoers
.
The output of echo $PATH
is misleading in this case. To see the path that sudo really uses, use printenv PATH
instead. In my case, the output looked like this:
The output doesn't contain /usr/pgsql-9.2/bin
, where psql lives, so it's not in sudo's path either.
To fix the problem you can add where psql lives to the secure_path
variable.
How to tell sudo where psql lives
Use sudo visudo
to open /etc/sudoers
in vi.
Bash Sudo Command Not Found
The file should contain a line like this:
This line sets the path for sudo. The part after the equals sign is the same as the output of the previous printenv PATH
example.
Replace it with something like this:
The replacement appends /usr/pgsql-9.2/bin
to the path list. The path list separator is a colon (:
).
Save and close the file.
To check that it worked, try the printenv PATH
command again:
Looks good!
Now try the psql -l
command:
It works!
Thanks to Drew Khoury who pointed me to a solution for a similar problem on Super User.
a small workaround - if you have no problem with executing more commands, you can switch user
and then
should work.