设置所有用户的Go路径时出现错误。

huangapple go评论83阅读模式
英文:

Error in setting go path for all user.

问题

我已经安装了Go并成功设置了其路径。
为了运行hello.py,我必须运行

   sudo go run hello.go 

但我想从以下位置运行它

  go run hello.go 

但它不起作用。我在.bashrc和.profile中进行了路径设置,我还需要做其他什么吗?

英文:

I have installed go and successfully setup it's path.
In order to run hello.py I have to run

   sudo go run hello.go 

but I want to run it from

  go run hello.go 

but it doesn't work. I did path setup in
.bashrc
and
.profile
do I have to do anything more?

答案1

得分: 1

尝试进行手动安装,完全在您的$HOME目录下进行(这样,root用户将不会参与,并且您不需要使用sudo命令)。

mkdir ~/golang
cd ~/golang
wget https://storage.googleapis.com/golang/go1.3.3.linux-amd64.tar.gz
tar -xzf go1.3.1.linux-amd64.tar.gz

将以下行添加到您的~/.bashrc文件中:

export GOROOT=$HOME/golang/go 
export PATH=$PATH:$GOROOT/bin
export GOPATH=~/golang/yourProjects

然后执行:

mkdir -p ~/golang/yourProjects/src

您可以开始使用~/golang/yourProjects/src/hello.go进行编程。

有关Go工作区(由$GOPATH引用的文件夹)的更多信息,请参阅“如何编写Go代码”。

英文:

Try to do a manual installation, entirely in your $HOME (that way, root is never involved, and you won't have to do any sudo.

mkdir ~/golang
cd ~/golang
wget https://storage.googleapis.com/golang/go1.3.3.linux-amd64.tar.gz
tar -xzf go1.3.1.linux-amd64.tar.gz

Add the following lines to your ~/.bashrc file:

export GOROOT=$HOME/golang/go 
export PATH=$PATH:$GOROOT/bin
export GOPATH=~/golang/yourProjects

Then

mkdir -p ~/golang/yourProjects/src

And you can start playing with ~/golang/yourProjects/src/hello.go.

See more about go workspace (the folder referenced by $GOPATH) in "How to Write Go Code".

huangapple
  • 本文由 发表于 2014年10月14日 02:10:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/26346252.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定