在Linux(Mint)中安装Go并修改bashrc文件

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

Installing Go in Linux(Mint) and modifying 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.

答案1

得分: 1

除其他事项外,您尝试将存储库克隆到~/go并编辑~/.bashrc以将$GOROOT指向~/gosource

仔细阅读Go 入门指南。要么复制并粘贴命令,要么在输入之前仔细检查您输入的内容;在按下回车键之前,请仔细检查输入内容。对于命令,$符号表示命令提示符,请不要输入它。请记住,Linux区分大小写,/\之间的区别很重要。非常仔细地检查命令的输出;输出是否合理。运行诊断命令,如envpwdwhichuname。当您在Stack Overflow答案中看到滚动条时,请滚动查看所有代码和输出。

首先,设置~/.bashrc

$ gedit ~/.bashrc

export GOROOT=$HOME/go
export GOARCH=amd64
export GOOS=linux
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN

关闭所有打开的终端窗口,然后打开一个新的终端窗口以检查新的~./bashrc和其他值。

$ env | grep '^\(GO\|HOME=\|PATH=\)'
GOBIN=/home/peter/go/bin
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/peter/go/bin
GOARCH=amd64
HOME=/home/peter
GOROOT=/home/peter/go
GOOS=linux
$ cd $GOROOT/src
$ pwd
/home/peter/go/src
$ uname -a
Linux peter 2.6.32-31-generic #61-Ubuntu SMP Fri Apr 8 18:25:51 UTC 2011 x86_64 GNU/Linux

然后将存储库克隆到$GOROOT,您将在同一位置克隆和编译。

$ hg clone -u release https://go.googlecode.com/hg/ $GOROOT
请求所有更改
添加变更集
添加清单
添加文件更改
添加了8441个变更集,对4421个文件进行了31916次更改(+1个头)
更新到分支release-branch.r57
更新了2702个文件,合并了0个文件,删除了0个文件,未解决0个文件
$ cd $GOROOT/src
$ ./all.bash
<剪辑输出>
所有测试通过
---
在/home/peter/go中为linux/amd64安装了Go。
在/home/peter/go/bin中安装了命令。
编译器是6g。
$ which 6g
/home/peter/go/bin/6g

您没有发布您的输出,所以我只能猜测您的问题是什么。

例如,您说“目录是Go”,应该是“go”;由于Linux区分大小写,“Go”和“go”是不同的。

如果您在hg clone命令中省略了$GOROOT目标或未设置$GOROOThg clone将默认为hg目录。例如,

$ env | grep '^GOROOT'
GOROOT=
$ hg clone -u release https://go.googlecode.com/hg/ $GOROOT
目标目录:hg

由于您有GOARCH=amd64,您应该在x86_64处理器上运行64位版本的Linux Mint。您的uname -a输出是什么?您希望6g6l程序在x86_64处理器上进行编译和链接,这应该在您的$GOBIN目录中,应该在您的$PATH中。

$ env | grep '^\(GOBIN\|PATH=\)'
GOBIN=/home/peter/go/bin
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/peter/go/bin
$ which 6g
/home/peter/go/bin/6g

您还应该通过阅读./all.bash命令输出的末尾来看到这一点。

所有测试通过
---
在/home/peter/go中为linux/amd64安装了Go。
在/home/peter/go/bin中安装了命令。
编译器是6g。
英文:

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 like env, pwd, which, and uname. When you see scroll bars in a Stack Overflow answer, scroll through all the code and output.

First, set up ~/.bashrc.

$ gedit ~/.bashrc

export GOROOT=$HOME/go
export GOARCH=amd64
export GOOS=linux
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN

Close any open terminal windows and then open a new terminal window to check the new ~./bashrc and other values.

$ env | grep '^\(GO\|HOME=\|PATH=\)'
GOBIN=/home/peter/go/bin
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/peter/go/bin
GOARCH=amd64
HOME=/home/peter
GOROOT=/home/peter/go
GOOS=linux
$ cd $GOROOT/src
$ pwd
/home/peter/go/src
$ uname -a
Linux peter 2.6.32-31-generic #61-Ubuntu SMP Fri Apr 8 18:25:51 UTC 2011 x86_64 GNU/Linux

Then clone the repository to $GOROOT and you will clone to and compile from the same place.

$ hg clone -u release https://go.googlecode.com/hg/ $GOROOT
requesting all changes
adding changesets
adding manifests
adding file changes
added 8441 changesets with 31916 changes to 4421 files (+1 heads)
updating to branch release-branch.r57
2702 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd $GOROOT/src
$ ./all.bash
< SNIP OUTPUT >
ALL TESTS PASSED
---
Installed Go for linux/amd64 in /home/peter/go.
Installed commands in /home/peter/go/bin.
The compiler is 6g.
$ which 6g
/home/peter/go/bin/6g

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 the hg clone command or $GOROOT is not set, hg clone will default to the hg directory. For example,

$ env | grep '^GOROOT'
GOROOT=
$ hg clone -u release https://go.googlecode.com/hg/ $GOROOT
destination directory: hg

Since you have GOARCH=amd64, you should be running a 64-bit version of Linux Mint on an x86_64 processor. What does your uname -a output say? You want the 6g and 6l programs to compile and link on an x86_64 processor, which should be in your $GOBIN directory, which should be in in your $PATH.

$ env | grep '^\(GOBIN\|PATH=\)'
GOBIN=/home/peter/go/bin
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/peter/go/bin
$ which 6g
/home/peter/go/bin/6g

You should also have seen this by reading the end of your ./all.bash command output.

ALL TESTS PASSED
---
Installed Go for linux/amd64 in /home/peter/go.
Installed commands in /home/peter/go/bin.
The compiler is 6g.

答案2

得分: 0

你应该输入

gedit ~/.bashrc

而不是

gedit /.bashrc

你能够保存它(?!)表明你要么在你的问题中打错了字,要么你以root用户身份运行了gedit。你需要以与将进行编译的用户(你的用户)相同的用户身份运行gedit,以确保你编辑的是正确的文件。

英文:

Instead of

gedit /.bashrc

you should have typed

gedit ~/.bashrc

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 run gedit as the same user (your user) that will be doing the compiling, to ensure that you edit the right file.

答案3

得分: 0

在最简单的情况下,不需要调整环境。

克隆之后,执行以下命令:

cd go/src
./all.bash

以编译Go语言。编译完成后,会告诉你安装的位置和如何运行它。然后,你可能想要真正修改你的环境来更新PATH变量。但是这个问题超出了Go语言的范围,所以按照Robin Green的建议去做。

附注:
golang的Debian软件包最近已经上传到不稳定版(参见此错误报告),所以也许从源代码包中获取并构建一个真正的Debian软件包会是一个更好的主意。

英文:

There's no need to tweak the environment in the simplest case.

After cloning, do

cd go/src
./all.bash

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.

huangapple
  • 本文由 发表于 2011年5月16日 23:33:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/6019717.html
匿名

发表评论

匿名网友

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

确定