I am reading a go book to learn go writing command line tools. In one of the examples I need to open firefox browser with an html file. The command run is:
browserPath,_ := exec.LookPath("firefox")
// Open the file on the browser
if err := exec.Command(browserPath, "index.html").Start(); err != nil {
return err
}
But get the error:
exec: "firefox": executable file not found in $PATH
My $PATH is:
$HOME/bin:/usr/local/bin:$PATH
I am running on mac with zsh. I looked at similar problems but can't solve it yet, anyone see what I am missing?
First of all thank you for reopening the question, I understand it might be trivial to many, but it can help someone else to see this answer.
The issue was (as @xarantolus commented) that my PATH did not contain the route to my /Applications
folder. Since I use zsh
and mac, I did the following steps to fix it:
First find where firefox executable was:
$ type -a firefox
Printed route:
firefox is /Applications/Firefox.app/Contents/MacOS/firefox
Now open zshrc file:
$ vim ~/.zshrc
Inside the file, my $PATH
was $HOME/bin:/usr/local/bin:$PATH
, and I added /Applications
so the line ended up like this:
export PATH=$HOME/bin:/usr/local/bin:/Applications/:$PATH
Notice that :$PATH
will be at end also after adding the new path
Then run command to reload .zshrc
source ~/.zshrc
If you dont use zsh, use the file .bashrc instead of .zshrc
Go could now see the firefox executable and it opened it as expected.