Score:2

export PATH="/usr/bin:$PATH" needed for every single command

np flag

so I was trying to set JAVA_HOME variable and some how I ended up facing this error every time I want to use terminal

Command 'poweroff' is available in the following places
* /sbin/poweroff
* /usr/sbin/poweroff
The command could not be located because '/sbin:/usr/sbin' is not included in the 
PATH environment variable.
This is most likely caused by the lack of administrative privileges associated with 
your user account.
poweroff: command not found

I can fix it with this command:

export PATH="/usr/bin:$PATH"

but every time I open new terminal I face the error again and I have to use this command again.

I would appreciate it if you could help. by the way I use Ubuntu 22.04.1 LTS

Score:6
cn flag

Although, since you accepted the question, it may be a stopgap that works for you, the better approach would be to fix the cause of the error. Unfortunately, in your question, you do not indicate how you set the JAVA_HOME variable. Somehow, you made changes somewhere that empty the PATH variable.

Thus, carefully inspect your .bashrc file. Anything that changes the PATH was added by yourself. By default, the PATH is not anymore modified in .bashrc. See /etc/skel/.bashrc for a default .bashrc file.

Score:2
es flag

Go to your home directory, edit .bashrc

Add your line:

export PATH="/usr/bin:$PATH"

Now your path will be exported every time you start a new terminal instance.

You can, of course, add any other path you want, before $PATH

Good luck.

Score:2
cn flag

The PATH is typically set in /etc/environment. Here's my version:

$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

Now, I don't know what you did to set your JAVA_HOME, but there are some examples like https://stackoverflow.com/questions/47013303/ubuntu-java-environment-path-bash-etc-environment-permission-denied which explain how to add JAVA_HOME to /etc/environment. If you followed this, but replaced the >> by a >, instead of adding to the existing file, you overwrote it. Which means the PATH is missing now.

Re-adding the PATH definition from my example should fix most issues, unless you have some package installed that adds yet another path component.

The advantage of doing this in /etc/environment, instead of .profile or .bashrc, is that it works for all users, including users that run server processes, instead of just for you.

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.