简体   繁体   English

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

[英]Installing Go in Linux(Mint) and modifying bashrc

I want to install Google's Go Language on my Linux Mint machine. 我想在我的Linux Mint机器上安装Google的Go语言。 I'm new to Linux so its not easy to follow some of the instructions I have read. 我是Linux的新手,所以不容易理解我读过的一些说明。 Namely, I have been told to edit/mod the bashrc file: 也就是说,我被告知编辑/修改bashrc文件:

 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 我输入了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). 因为我然后尝试编译代码并且出现了一长串错误(我没有 - 我很遗憾地使用了不同的PC)。

But if anyone can help me install Go, I'd appreciate it. 但如果有人可以帮我安装Go,我会很感激。

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. 在golang.com安装页面的顶部提到了哪些内容。

Amongst other things, you tried to clone the repository to ~/go and edited ~/.bashrc to point $GOROOT to ~/gosource . 除此之外,您尝试将存储库克隆到~/go并编辑~/.bashrc以将$GOROOT指向~/gosource

Read the Go Getting Started instructions carefully. 请仔细阅读Go Getting Started说明。 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. 请记住,Linux区分大小写,而且/\\之间的区别非常重要。 Check the output of commands very carefully; 仔细检查命令的输出; does the ouput make sense. 输出是否有意义。 Run diagnostic commands like env , pwd , which , and uname . 运行envpwdwhichuname等诊断命令。 When you see scroll bars in a Stack Overflow answer, scroll through all the code and output. 当您在Stack Overflow应答中看到滚动条时,滚动浏览所有代码和输出。

First, set up ~/.bashrc . 首先,设置~/.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. 关闭所有打开的终端窗口,然后打开一个新的终端窗口以检查新的~./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

Then clone the repository to $GOROOT and you will clone to and compile from the same place. 然后将存储库克隆到$GOROOT ,您将从同一个地方克隆并编译。

$ 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"; 例如,你说“目录是Go”,它应该是“go”; since Linux is case sensitive, "Go" and "go" are different. 由于Linux区分大小写,“Go”和“go”是不同的。

If you omit the $GOROOT destination from the hg clone command or $GOROOT is not set, hg clone will default to the hg directory. 如果从hg clone命令中省略$GOROOT目标或未设置$GOROOT ,则hg clone将默认为hg目录。 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. 由于您有GOARCH=amd64 ,因此您应该在x86_64处理器上运行64位版本的Linux Mint。 What does your uname -a output say? 你的uname -a输出说什么? 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 . 您希望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

You should also have seen this by reading the end of your ./all.bash command output. 您还应该通过阅读./all.bash命令输出的结尾来看到这一点。

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

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. 您能够保存它(?!)的事实表明您错误地记录了您在问题中实际输入的内容,或者您​​是以root身份运行gedit 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. 您需要将gedit作为将要进行编译的同一用户(您的用户)运行,以确保您编辑正确的文件。

There's no need to tweak the environment in the simplest case. 在最简单的情况下,无需调整环境。

After cloning, do 克隆后,做

cd go/src
./all.bash

to get Go compiled. 得到Go编译。 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. 然后,您可能希望真正修改环境以更新PATH变量。 But this question is really out of scope of the Go language, so do what Robin Green suggested. 但这个问题实际上超出了Go语言的范围, 罗宾格林提出的建议也是如此。

PS 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. PS golang的Debian软件包最近被上传到unstable(看到这个bug ),所以抓住源代码包并从中构建一个真正的Debian软件包可能会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM