Linux(Mint)安装Go并修改bashrc
我想在我的 Linux Mint 机器上安装 Google 的 Go 语言。我是 Linux 新手,所以遵循我读过的一些说明并不容易。也就是说,我被告知要编辑/修改 bashrc 文件:
export GOROOT=$HOME/gosource
export GOARCH=amd64
export GOOS=linux
export GOBIN=$HOME/bin
export PATH=$PATH:$GOBIN
我不知道该怎么做。我
在终端中输入 gedit ~/.bashrc
,然后出现了一个空白页面。我输入了代码并保存了它。然后就
hg clone -u https://go.googlecode.com/hg/ go
得到了源代码。这是正确的吗?因为然后我尝试编译代码并出现一长串错误(我没有 - 不幸的是我正在使用另一台电脑)。
但如果有人能帮助我安装 Go,我将不胜感激。
解决方案:
除了下面的答案中提到和解决的各种问题之外,我还忘记安装
sudo apt-get install bison ed gawk gcc libc6-dev make
golang.com 安装页面顶部提到的以下内容。
I want to install Google's Go Language on my Linux Mint machine. I'm new to Linux so its not easy to follow some of the instructions I have read. Namely, I have been told to edit/mod the bashrc file:
export GOROOT=$HOME/gosource
export GOARCH=amd64
export GOOS=linux
export GOBIN=$HOME/bin
export PATH=$PATH:$GOBIN
I don't know how to do this. I typed gedit ~/.bashrc
into the terminal and a blank page appeared. I put in the code and saved it. Then did
hg clone -u https://go.googlecode.com/hg/ go
to get the source code. Is this correct? Because I then tried to compile the code and a long list of errors appeared (which I don't have - I'm using a different PC at the mo unfortunately).
But if anyone can help me install Go, I'd appreciate it.
SOLUTION:
Aside from various problems mentioned and solved in the answers below, I had forgotten to install the following
sudo apt-get install bison ed gawk gcc libc6-dev make
WHich is mentioned at the top of the golang.com install page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除此之外,您尝试将存储库克隆到
~/go
并编辑~/.bashrc
将$GOROOT
指向~ /gosource
。仔细阅读 Go 入门 说明。复制并粘贴命令或仔细检查您键入的内容;在按回车键之前,请仔细检查输入。对于命令,
$
符号代表命令提示符,请勿键入。请记住,Linux 区分大小写,/
和\
之间的区别很重要。非常仔细地检查命令的输出;输出有意义吗?运行env
、pwd
、which
和uname
等诊断命令。当您在 Stack Overflow 答案中看到滚动条时,滚动浏览所有代码和输出。首先,设置
~/.bashrc
。关闭所有打开的终端窗口,然后打开一个新的终端窗口以检查新的
~./bashrc
和其他值。然后将存储库克隆到 $GOROOT,您将克隆到同一位置并从同一位置进行编译。
你还没有发布你的输出,所以我只能猜测你的问题是什么。
比如你说“目录是Go”,应该是“go”;由于 Linux 区分大小写,因此“Go”和“go”是不同的。
如果您在
hg clone
命令中省略$GOROOT
目标或未设置$GOROOT
,则hgclone
将默认为hg
目录。例如,由于您有
GOARCH=amd64
,因此您应该在x86_64
处理器上运行 64 位版本的 Linux Mint。您的uname -a
输出内容是什么?您希望6g
和6l
程序在x86_64
处理器上编译和链接,该处理器应位于您的$GOBIN
目录,该目录应位于您的$PATH
中。您还应该通过阅读
./all.bash
命令输出的末尾看到这一点。Amongst other things, you tried to clone the repository to
~/go
and edited~/.bashrc
to point$GOROOT
to~/gosource
.Read the Go Getting Started instructions carefully. Either copy and paste commands or check what you type very carefully; check input very carefully before you hit enter. For commands, the
$
sign represents the command prompt, don't type it. Remember, Linux is case sensitive and the distinction between/
and\
is important. Check the output of commands very carefully; does the ouput make sense. Run diagnostic commands likeenv
,pwd
,which
, anduname
. When you see scroll bars in a Stack Overflow answer, scroll through all the code and output.First, set up
~/.bashrc
.Close any open terminal windows and then open a new terminal window to check the new
~./bashrc
and other values.Then clone the repository to
$GOROOT
and you will clone to and compile from the same place.You haven't posted your output, so I can only guess what your problems are.
For example, you say "the directory is Go", it should be "go"; since Linux is case sensitive, "Go" and "go" are different.
If you omit the
$GOROOT
destination from thehg clone
command or$GOROOT
is not set,hg clone
will default to thehg
directory. For example,Since you have
GOARCH=amd64
, you should be running a 64-bit version of Linux Mint on anx86_64
processor. What does youruname -a
output say? You want the6g
and6l
programs to compile and link on anx86_64
processor, which should be in your$GOBIN
directory, which should be in in your$PATH
.You should also have seen this by reading the end of your
./all.bash
command output.而不是
你应该输入
Thefact that you were able to save it(?!) 表明你要么打错了你在问题中实际输入的内容,要么你以 root 身份运行
gedit
。您需要以将进行编译的同一用户(您的用户)身份运行gedit
,以确保您编辑正确的文件。Instead of
you should have typed
The fact that you were able to save it(?!) indicates that either you typo'd what you actually typed in your question, or you were running
gedit
as root. You need to rungedit
as the same user (your user) that will be doing the compiling, to ensure that you edit the right file.在最简单的情况下无需调整环境。
克隆后,进行
Go 编译。编译后,您将被告知它的安装位置以及如何运行它。然后您可能想要真正修改您的环境以更新
PATH
变量。但这个问题确实超出了 Go 语言的范围,所以按照 Robin Green 的建议去做。聚苯乙烯
golang 的 Debian 软件包最近已上传到不稳定的版本(请参阅此错误< /a>),所以获取源包并从中构建真正的 Debian 包可能是一个更好的主意。
There's no need to tweak the environment in the simplest case.
After cloning, do
to get Go compiled. After compiling you'll be told where it's installed and how to run it. Then you might want to really modify your environment to update the
PATH
variable. But this question is really out of scope of the Go language, so do what Robin Green suggested.P.S.
The Debian packages for golang have recently been uploaded to unstable (see this bug), so may be it would be a better idea to grab the source package and build a real Debian package(s) from it.