go1.10.1 linux/amd64
debian 9
installing go
There is a paragraph
"Add /usr/local/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile (for a system-wide installation) or $HOME/.profile"
under "Install the Go tools" header.
It would be nice to append "... or $HOME/.bashrc" there.
https://golang.org/doc/install
How so? Putting environments in .profile or .bash_profile is better than .bashrc, as it gets executed only once per login instead of on every interactive shell. And the environment variable will also be available even when there isn't an interactive shell involved.
If this is about you having modified .profile but not seeing its effect, it's because you need to log out and log back into your user session. Perhaps that should be explicitly mentioned in the install guide.
If your .profile is idempotent, you don't even need to log out: you can just source it again in the current shell. (But I agree that we should mention that in the doc.)
I've found solution here: https://wiki.debian.org/EnvironmentVariables
_Graphical logins do not read a shell's startup files (/etc/profile and ~/.profile and so on) by default, but you as a user may choose to create a ~/.xsessionrc file which does this._
So i created ~/.xsessionrc and added
if [ -f ~/.profile ]; then
. ~/.profile
fi
And it works after logout and login again. Should I remove this issue from list as my mistake?
It would still be good to mention the bit about logging out and in (or sourcing the file again). Would you like to send a PR ?
Since you encountered it first hand, you can probably write in a manner suited for people who can stumble into this issue again.
Probably someone more experienced can do it. Text to append on page (for Linux section):
For logging in with graphical display manager you should create or edit file ~/.xsessionrc and put there:
if [ -f ~/.profile ]; then
. ~/.profile
fi
Then log out and log in again.
I think the advice should be more generic, or link to a page on the internet covering common issues with shell profile files. Otherwise, this advice is only going to apply to certain Linux systems that use X11, potentially further confusing users that don't have that setup.
Agree. I think it would be better someone Linux seasoned and with fluent english write this text because I'm new to Linux.
Change https://golang.org/cl/105557 mentions this issue: doc: add a note about loading profile files
Debian based distros now have /etc/profile.d.
The above is written for go-1.9.2 using gcc-4.7.1 , and I cited therein V. Batts' .SlackBuild, which obviously in 2018 has been updated.
Linux, Mac OS X, and FreeBSD tarballs
Using the path for the go executable from the above section, V. Batts $GOROOT_FINAL in the below would be/usr/local/go.
# Put the profile scripts for setting PATH and env variables
mkdir -p $PKG/etc/profile.d
cat > $PKG/etc/profile.d/go.csh << EOF
#!/bin/csh
setenv GOROOT ${GOROOT_FINAL}
setenv PATH \${GOROOT}/bin:\${PATH}
EOF
cat > $PKG/etc/profile.d/go.sh << EOF
#!/bin/sh
export GOROOT="${GOROOT_FINAL}"
export PATH="\${GOROOT}/bin:\${PATH}"
EOF
chmod 0755 $PKG/etc/profile.d/go.csh
chmod 0755 $PKG/etc/profile.d/go.sh
Such an executable shell script can also be sourced.
#!/bin/sh
export GOROOT=/usr/local/go
export PATH=${GOROOT}/bin:${PATH}
https://github.com/golang/go/wiki/SettingGOPATH
Perhaps the idea for the use of a shell's rc file came from the above Wiki Page.
Most helpful comment
How so? Putting environments in
.profileor.bash_profileis better than.bashrc, as it gets executed only once per login instead of on every interactive shell. And the environment variable will also be available even when there isn't an interactive shell involved.