Score:3

"sudo command" not working, but after sudo su when I enter command is working

be flag

My Ubuntu version is Ubuntu 22.04.2 LTS. I have one user (ahmet) and it is member of sudo. I download intellij idea and I want to use its mvn lib for everyone. I edited /etc/bash.bashrc as in this link https://linuxhint.com/add-path-permanently-linux/ . When I try to execute mvn, there is three situtations:

normal way:

ahmet@ahmet:~$ mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /opt/idea-IU-231.8109.175/plugins/maven/lib/maven3
Java version: 11.0.18, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.19.0-41-generic", arch: "amd64", family: "unix"

as root:

ahmet@ahmet:~$ sudo su
root@ahmet:/home/ahmet# mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /opt/idea-IU-231.8109.175/plugins/maven/lib/maven3
Java version: 11.0.18, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.19.0-41-generic", arch: "amd64", family: "unix"

with sudo:

ahmet@ahmet:~$ sudo mvn -v
sudo: mvn: command not found

In my opinion, with "sudo mvn -v", everything must be same for root (#). But in this case, root can execute but normal user which is member of sudo, cannot use mvn with sudo. What is the problem?

Ahmet Hakan YILDIZ avatar
be flag
Yes, full path method worked for me and I understand why it did not work before. Thank you!
luca.vercelli avatar
kz flag
Just to better understand your problem, why exactly should you run maven as root? it should not be necessary.
Score:0
jp flag

When you run sudo mvn -v directly from your user account, the system does not find the mvn command because the mvn executable directory is not included in your user's PATH.

You can add the full path to /root/.bashrc to fix this.

Like this

export PATH=$PATH:/opt/idea-IU-231.8109.175/plugins/maven/lib/maven3/bin
muru avatar
us flag
`sudo <command>` doesn't run a shell, so this wouldn't help.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.