英文:
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".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论