I am following the "How to Write Code" portion of the golang docs, here. I am also using fish fish shell.
I have followed the tutorial and set the proper environment variables (GOPATH and PATH) but I can't get the command go install github.com/user/hello
to work with my installation.
I am getting an error:
can't load package: package github.com/user/hello: import "github.com/user/hello": cannot find package
It does this by adding the components either to $fish_user_paths or directly to $PATH (if the --path switch is given). It is (by default) safe to use fish_add_path in config. fish, or it can be used once, interactively, and the paths will stay in future because of universal variables.
At least by default, PATH is a global variable, which means it is per-session. That means to change something from $PATH, either remove it from where it is added (which is likely outside of fish since it inherits it), or put the set -e call in your ~/. config/fish/config. fish so it will be executed on every start.
To be able to run fish scripts from your terminal, you have to do two things. Add the following shebang line to the top of your script file: #!/usr/bin/env fish . Mark the file as executable using the following command: chmod +x <YOUR_FISH_SCRIPT_FILENAME> .
If you wish to use fish (or any other shell) as your default shell, you need to enter your new shell's executable /usr/local/bin/fish in two places: add /usr/local/bin/fish to /etc/shells. change your default shell with chsh -s to /usr/local/bin/fish.
I had, in fact, incorrectly set my environment variables. Specifically, when setting GOPATH in my ~/.config/fish/config.fish
file I needed to export the variable.
Put these lines in your config.fish for fish shell to use Go:set -x GOPATH $HOME/path/to/your/workspace
Note the -x. That was what was missing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With