0

on trying to configurate go programming language i messed up my PATH in linux. I can not do any commands without specifing the path:

frede@frede-Lenovo-V110-15ISK:~$ ls
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH environment variable.
ls: command not found
frede@frede-Lenovo-V110-15ISK:~$ echo $PATH
/home/frede/bin:/home/frede/.local/bin:PATH:/home/frede/go/bin

However I can run it with the specified path. I tried to solve this problem at looking at similar threads, but I just couldn't find the solution for me. Can you please help me?

UPDATE

frede@frede-Lenovo-V110-15ISK:~$ grep 'PATH=' ~/.profile ~/.bashrc ~/.bash_profile /etc/profile
/home/frede/.profile:PATH="$HOME/bin:$HOME/.local/bin:$PATH"
/home/frede/.bashrc:export GOPATH=/home/frede/go
/home/frede/.bashrc:export PATH=PATH:/home/frede/go/bin
grep: /home/frede/.bash_profile: No such file or directory
FrontMobe
  • 115
  • 1
    Please [edit] your question and i) replace the output you show with the output of LC_ALL=C ls, that will give you English error messages; ii) show us the output of grep 'PATH=' ~/.profile ~/.bashrc ~/.bash_profile /etc/profile. – terdon Mar 12 '18 at 11:15
  • Looks like a typo of PATH=PATH... instead of PATH=$PATH... – Jeff Schaller Mar 12 '18 at 11:16
  • 1
    You need to correct this line export PATH=PATH:/home/frede/go/bin in your /home/frede/.bashrc file into export PATH="$PATH":/home/frede/go/bin. –  Mar 12 '18 at 11:51
  • This is a protected file. I tried to vi/vim once and completely messed up a file, so will this do it as well? echo "export PATH=$PATH:/home/frede/go/bin >> ~./bashrc" ? – FrontMobe Mar 12 '18 at 11:54
  • No, that particular line has to be fixed. You can echo, but that line needs to be removed then. –  Mar 12 '18 at 11:56
  • Open it with a normal editor. vi/m is difficult (easy to break things). –  Mar 12 '18 at 11:57
  • And your echo command is not correct, so better just use a simple editor. –  Mar 12 '18 at 11:58
  • Ok, thank you. I first tried to edit the /etc/.barshrc which is private. But its the /home/Frede/.bashrc , just as you said it. Works now all for me. Thanks a lot guys – FrontMobe Mar 12 '18 at 12:02

1 Answers1

1

Restore

There should be a right PATH in your /etc/profile. I don't know how you messed up your PATH, but sourcing /etc/profile should bring things back to normal. As long as you didn't edit that one. So try this:

. /etc/profile

Proper PATH setup

Assuming you're using bash, you might make use of .bashrc file (instead of .profile) to setup your path. You can use a similar entry to the one you might find within /etc/profile:

# set PATH so it includes your private Go bin folder if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/go/bin:$PATH"
fi

If you aren't using bash, adjust the PATH (same way as above) in your private .profile file instead of .bashrc.

Finally, source the file you've modified:

. ~/.bashrc   # or
. ~/.profile

(note: .profile usually sources .bashrc -- see references for further info)

And if you've polluted some of your files with an erroneous PATH definition, you need to clean that up. Follow Terdon's comment under your question for this.

References