英文:
GOPATH variable not persisting
问题
我正在使用export GOPATH=$HOME/go
来设置$GOPATH,按照Go语言的说明,一切都正常。当我使用echo
命令输出路径时,显示的是我设置的路径。
然而,如果我关闭终端并重新打开,$GOPATH将不再是我设置的值。
我猜我的问题是如何使新的$GOPATH持久化?
英文:
I'm setting the $GOPATH using export GOPATH=$HOME/go
as per GoLang's instructions and everything works fine. When I echo
out the path it shows what I set it to.
However, if I close my terminal and re-open it the $GOPATH is no longer what I set it to.
I guess my question is how can I make the new $GOPATH persist?
答案1
得分: 0
打开你的终端(你可以使用任何文本编辑器,比如:gedit、vi或vim)。
gedit ~/.bashrc
转到文件末尾,并编辑以下行:
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
假设/usr/lib/go是你的GOROOT
要知道你的GOROOT,可以执行以下操作:
go env
或者
which go
英文:
Open you terminal (you can use any text editor, like: gedit, vi or vim).
gedit ~/.bashrc
go to the end of file and edit with the following lines:
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
Assuming that /usr/lib/go is your GOROOT
to know your GOROOT you can do:
go env
or
which go
答案2
得分: 0
只是让你知道,这个问题应该在SuperUser或其他地方以一般形式回答,而不是在这里。无论如何,以下是使得这个设置在你的会话中始终生效的步骤:
cd ~
vi .bashrc
//向下翻页,如果不是新文件,滚动到文件底部
按下 i 进入插入模式,在底部添加 export GOPATH=$HOME/go
按下 escape 键
输入 :w 保存文件
输入 :q 退出编辑器
英文:
Just so you know this should be answered in general form on SuperUser or something other than here. Regardless here's the steps to make it so this is always set in your session;
cd ~
vi .bashrc
//page down, end whatever to get to bottom of file if it's not new
press i to insert, add export GOPATH=$HOME/go
press escape
:w
:q
答案3
得分: 0
为了让Felix的答案更简单,您可以运行以下命令,而无需费心使用vim
:
echo "export GOPATH=$HOME/go" >> ~/.bash_profile
echo "export PATH=$GOPATH/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile
英文:
To make Felix's answer more simpler you could run the below commands while not breaking your head with vim
echo "export GOPATH=$HOME/go" >> ~/.bash_profile
echo "export PATH=$GOPATH/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论