英文:
How to install the current version of Go in Ubuntu Precise
问题
运行 sudo apt-get install golang-stable
,我得到了 Go 版本 go1.0.3
。有没有办法安装 go1.1.1
?
英文:
Running sudo apt-get install golang-stable
, I get Go version go1.0.3
. Is there any way to install go1.1.1
?
答案1
得分: 163
对于获取最新版本:
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go
还可以参考wiki
英文:
[Updated (previous answer no longer applied)]
For fetching the latest version:
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go
Also see the wiki
答案2
得分: 104
我喜欢在我的Ubuntu系统中使用GVM来管理我的Go版本。使用起来非常简单,如果你熟悉RVM,那就更容易上手了。它允许你在系统中安装多个Go版本,并在任何时候切换到你想要的版本。
使用以下命令安装GVM:
sudo apt-get install bison mercurial
bash < <(curl -LSs 'https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer')
. "$HOME/.gvm/scripts/gvm"
然后,只需执行以下命令即可:
gvm install go1.1.1
gvm use go1.1.1 --default
第二个命令末尾的default标志将把go1.1.1设置为您在启动新的终端会话时的默认Go版本。
英文:
I like to use GVM for managing my Go versions in my Ubuntu box. Pretty simple to use, and if you're familiar with RVM, it's a nobrainer. It allows you to have multiple versions of Go installed in your system and switch between whichever version you want at any point in time.
Install GVM with:
sudo apt-get install bison mercurial
bash < <(curl -LSs 'https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer')
. "$HOME/.gvm/scripts/gvm"
and then it's as easy as doing this:
gvm install go1.1.1
gvm use go1.1.1 --default
The default flag at the end of the second command will set go1.1.1 to be your default Go version whenever you start a new terminal session.
答案3
得分: 42
我从GoLang官方仓库使用了以下命令,它在我的Ubuntu 14.04上安装了GoLang版本1.6。
sudo add-apt-repository ppa:ubuntu-lxc/lxd-stable
sudo apt-get update
sudo apt-get install golang
然而,自从创建这个答案以来,针对Ubuntu 18.04、20.04或22.04(amd64、arm64或armhf)的指令已经更新为以下内容:
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go
参考官方GoLang仓库https://github.com/golang/go/wiki/Ubuntu,看起来这个ppa将来会持续更新。
英文:
I used following commands from GoLang official repository,
it installed GoLang version 1.6 on my Ubuntu 14.04
sudo add-apt-repository ppa:ubuntu-lxc/lxd-stable
sudo apt-get update
sudo apt-get install golang
However, since this answer was created, the instructions have been updated to these, for Ubuntu 18.04, 20.04 or 22.04 (amd64, arm64 or armhf):
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go
Reference official GoLang Repo https://github.com/golang/go/wiki/Ubuntu it seems this ppa will always be updated in future.
答案4
得分: 27
[2015年10月]
回答是因为当前接受的答案sudo apt-get install golang
已经过时了,如果你不想安装GVM
,请按照以下步骤进行安装。
逐步安装过程:##
- 在这里下载最新版本(操作系统:Linux)。
- 打开终端并进入下载目录。
sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
- 将
go
添加到你的路径中export PATH=$PATH:/usr/local/go/bin
- 使用
go version
检查当前安装的版本。 - 开始编程。
可能的错误+修复方法:(待更新)##
如果你得到一个go version xgcc (Ubuntu 4.9.1-0ubuntu1) 4.9.1 linux/amd64
的错误信息,那么你做错了什么,请查看这篇帖子:https://stackoverflow.com/questions/29514456/go-is-printing-xgcc-version-but-not-go-installed-version
英文:
[October 2015]
Answer because the current accepted answersudo apt-get install golang
isn't uptodate and if you don't want to install GVM
follow these steps.
Step by step installation:
- Download the latest version here (OS: Linux).
- Open your terminal and go to your Downloads directory
sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
- Add
go
to your pathexport PATH=$PATH:/usr/local/go/bin
go version
to check the current version installed- Start programming.
Possible errors + fixes: (to be updated)
If you get a go version xgcc (Ubuntu 4.9.1-0ubuntu1) 4.9.1 linux/amd64
then you did something wrong, so check out this post: https://stackoverflow.com/questions/29514456/go-is-printing-xgcc-version-but-not-go-installed-version
答案5
得分: 18
我从源代码安装。这里有一个逐步教程:http://golang.org/doc/install/source
英文:
i installed from source. there is a step-by-step tutorial here: http://golang.org/doc/install/source
答案6
得分: 9
这是我找到的在Ubuntu 14.04上安装go的最直接和简单的方法,不需要任何ppa或其他工具。
目前,GO的版本是1.7
使用wget获取Go 1.7.tar.gz
wget https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz
解压并将其复制到/usr/local/
sudo tar -C /usr/local -xzvf go1.7.linux-amd64.tar.gz
现在,您已成功安装了GO。现在您需要设置环境变量,以便可以从任何地方使用go
命令。
为了实现这一点,我们需要在.bashrc
中添加一行
所以,
sudo nano ~/.bashrc
并在文件末尾添加以下行。
export PATH="/usr/local/go/bin:$PATH"
现在,go/bin
中的所有命令都将起作用。
通过执行以下命令检查安装是否成功
go version
对于离线文档,您可以执行以下操作
godoc -http=:6060
离线文档将在http://localhost:6060
上可用
注意:
这里有些人建议更改PATH变量。
这不是一个好选择。
-
将其更改为
/usr/local/go/bin
是临时的,一旦关闭终端,它将重置。 -
go
命令只能在更改了PATH值的终端中工作。 -
您将无法使用任何其他命令,如
ls,nano
或几乎所有其他命令,因为其他所有命令都在/usr/bin
或其他位置。所有这些东西将停止工作,并且会出现错误。
然而,这是永久的,不会干扰其他任何东西。
英文:
Here is the most straight forward and simple method I found to install go on Ubuntu 14.04 without any ppa or any other tool.
As of now, The version of GO is 1.7
Get the Go 1.7.tar.gz using wget
wget https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz
Extract it and copy it to /usr/local/
sudo tar -C /usr/local -xzvf go1.7.linux-amd64.tar.gz
You have now successfully installed GO. Now You have to set Environment Variables so you can use the go
command from anywhere.
To achieve this we need to add a line to .bashrc
So,
sudo nano ~/.bashrc
and add the following line to the end of file.
export PATH="/usr/local/go/bin:$PATH"
Now, All the commands in go/bin
will work.
Check if the install was successful by doing
go version
For offline Documentation you can do
godoc -http=:6060
Offline documentation will be available at http://localhost:6060
NOTE:
Some people here are suggesting to change the PATH variable.
It is not a good choice.
-
Changing that to
/usr/local/go/bin
is temporary and it'll reset once you close terminal. -
go
command will only work in terminal in which you changed the value of PATH. -
You'll not be able to use any other command like
ls, nano
or just about everything because everything else is in/usr/bin
or in other locations. All those things will stop working and it'll start giving you error.
However, this is permanent and does not disturbs anything else.
答案7
得分: 9
-
删除现有的Go版本:
sudo apt-get purge golang*
-
安装最新版本的Go:
sudo add-apt-repository ppa:longsleep/golang-backports sudo apt-get update sudo apt-get install golang-go
-
在主目录下创建
.profile
文件,并添加以下内容:# ~/.profile: 由登录shell的命令解释器执行。 # 如果~/.bash_profile或~/.bash_login存在,则bash(1)不会读取此文件。 # 有关示例,请参阅/usr/share/doc/bash/examples/startup-files。 # 这些文件位于bash-doc软件包中。 # 默认的umask设置在/etc/profile中;要为ssh登录设置umask,请安装并配置libpam-umask软件包。 #umask 022 # 如果正在运行bash if [ -n "$BASH_VERSION" ]; then # 如果存在.bashrc,则包含它 if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi # 设置PATH以包括用户的私有bin目录 PATH="$HOME/bin:$HOME/.local/bin:$PATH"
-
将Go工作区设置为环境变量:
GOPATH=~/.go
-
应用
.profile
配置:source ~/.profile
测试:
$ go version
go version go1.11.1 linux/amd64
英文:
I use this instruction to install the latest version of <sub><img src="https://i.stack.imgur.com/R27Lx.png" width="24" height="32" alt="IMG: " title="golang"></sub>
-
Remove the existing Go version:
sudo apt-get purge golang*
-
Install the latest version of Go:
sudo add-apt-repository ppa:longsleep/golang-backports sudo apt-get update sudo apt-get install golang-go
-
Create the
.profile
file in the home path with this content:# ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. # see /usr/share/doc/bash/examples/startup-files for examples. # the files are located in the bash-doc package. # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022 # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi # set PATH so it includes user's private bin directories PATH="$HOME/bin:$HOME/.local/bin:$PATH"
-
Set Go workspace to the environment variable:
GOPATH=~/.go
-
Apply the
.profile
configuration:source ~/.profile
Test:
$ go version
go version go1.11.1 linux/amd64
答案8
得分: 6
对于当前版本的Go:
> Go编程语言
>
> 入门指南
>
> 下载Go发行版
>
> 下载
>
> 点击上面的链接访问Go项目的下载页面,并选择与您的操作系统和处理器架构匹配的二进制发行版。
>
> 官方二进制发行版适用于FreeBSD、Linux、macOS和Windows操作系统以及32位(386)和64位(amd64)x86处理器架构。
>
> 如果您的操作系统和架构组合没有可用的二进制发行版,您可以尝试从源代码安装或安装gccgo而不是gc。
>
>
> 从源代码安装Go
英文:
For the current release of Go:
> The Go Programming Language
>
> Getting Started
>
> Download the Go distribution
>
> Downloads
>
>
> Click the link above to visit the Go project's downloads page and
> select the binary distribution that matches your operating system and
> processor architecture.
>
> Official binary distributions are available for the FreeBSD,
> Linux, macOS, and Windows
> operating systems and the 32-bit (386) and 64-bit (amd64) x86
> processor architectures.
>
> If a binary distribution is not available for your combination of
> operating system and architecture you may want to try installing from
> source or installing gccgo instead of gc.
>
>
> Installing Go from source
答案9
得分: 6
如果有人想要安装Go 1.8,请按照以下步骤进行操作:
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update
sudo apt-get install golang-go
然后安装Go
sudo apt-get install golang-1.8-go
英文:
If someone is looking for installing Go 1.8 the follow this:
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update
sudo apt-get install golang-go
And then install go
sudo apt-get install golang-1.8-go
答案10
得分: 5
wget https://storage.googleapis.com/golang/go1.6beta1.linux-amd64.tar.gz -o /tmp/go1.6beta1.linux-amd64.tar.gz
sudo tar -zxvf go1.6beta1.linux-amd64.tar.gz -C /usr/local/bin/
mkdir ~/go
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
export GOROOT=/usr/local/bin/go
export PATH=$PATH:$GOROOT/bin
go version
should show be
go version go1.6beta1 linux/amd64
go env
should show be
GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/vats/go" GORACE="" GOROOT="/usr/local/bin/go" GOTOOLDIR="/usr/local/bin/go/pkg/tool/linux_amd64" GO15VENDOREXPERIMENT="1" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0" CXX="g++" CGO_ENABLED="1"
英文:
> 1. Download say, go1.6beta1.linux-amd64.tar.gz
from https://golang.org/dl/
into /tmp
wget https://storage.googleapis.com/golang/go1.6beta1.linux-amd64.tar.gz -o /tmp/go1.6beta1.linux-amd64.tar.gz
> 2. un-tar into /usr/local/bin
sudo tar -zxvf go1.6beta1.linux-amd64.tar.gz -C /usr/local/bin/
> 3. Set GOROOT, GOPATH, [on ubuntu add following to ~/.bashrc]
mkdir ~/go
export GOPATH=~/go
export PATH=$PATH:$GOPATH/bin
export GOROOT=/usr/local/bin/go
export PATH=$PATH:$GOROOT/bin
>4. Verify
go version
should show be
>go version go1.6beta1 linux/amd64
go env
should show be
>GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/vats/go"
GORACE=""
GOROOT="/usr/local/bin/go"
GOTOOLDIR="/usr/local/bin/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
答案11
得分: 4
这些天根据golang github with for Ubuntu,可以通过snap轻松安装最新版本的Go:
使用snaps也非常好用:
# 这将为您提供最新版本的go
$ sudo snap install --classic go
可能比纠结于过时和/或第三方PPA更可取
英文:
These days according to the golang github with for Ubuntu, it's possible to install the latest version of Go easily via a snap:
> Using snaps also works quite well:
# This will give you the latest version of go
$ sudo snap install --classic go
Potentially preferable to fussing with outdated and/or 3rd party PPAs
答案12
得分: 2
在最近的Ubuntu(20.10)上,sudo apt-get install golang
可以正常工作;它将安装1.14版本。
英文:
On recent Ubuntu (20.10) sudo apt-get install golang
works fine; it will install version 1.14.
答案13
得分: 0
或者你可以使用这个脚本来安装Go和LiteIDE?
如果你对提供的答案不满意,请留下评论而不是盲目地投票反对。我在过去的4年中一直使用这个设置而没有任何问题。
英文:
Or maybe you could use this script to install Go and LiteIDE?
If you are unhappy with the answer provided, please comment instead of blindly down voting. I have used this setup for the last 4 years without any issue.
答案14
得分: 0
你也可以使用update-golang脚本:
update-golang是一个脚本,可以方便地获取和安装新的Golang版本,最小化系统干扰
git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh
英文:
You can also use the update-golang script:
update-golang is a script to easily fetch and install new Golang releases with minimum system intrusion
git clone https://github.com/udhos/update-golang
cd update-golang
sudo ./update-golang.sh
答案15
得分: 0
这是一个旧问题,在2022年已经过去了将近9年。但我认为自动化这个安装过程很重要。
要求:
- 在Ubuntu 18和20上进行了测试。
- 必须是sudo用户,您必须能够使用
sudo
命令。
安装:
- 使用以下命令创建一个新文件:
touch ~/go-installer.sh
- 使用任何可用的编辑器(如vi、vim或nano)编辑该文件。
nano ~/go-installer.sh
- 将以下脚本粘贴到文件中:
#!/bin/bash
## 定义版本和构建
VERSION=1.19
BUILD=4
## 定义软件包名称
PKG_NAME='go'
## 定义Go官方网址
GO_URL='https://golang.org/dl/'
## 定义本地路径
LOCAL_PATH='/usr/local'
## 定义系统库路径
LIB_PATH='/usr/lib'
## 定义系统二进制路径
BIN_PATH='/usr/bin'
## 定义环境变量脚本文件名
EV_FILE='/etc/profile.d/go-bin-path.sh'
## 定义导出路径命令
EXPORT_CMD='export PATH=$PATH:/usr/local/go/bin'
## 定义脚本内容
SCRIPT='#!/bin/sh\n'${EXPORT_CMD}
## 定义用户主目录
USER_HOME_DIR=$(getent passwd ${SUDO_USER:-$USER} | cut -d: -f6)
check_command() {
[ -x "$(command -v $PKG_NAME)" ] && echo 0 || echo 1
}
test_package() {
echo
code=$(check_command)
[ $code -eq 0 ] && go version || echo "Error: $PKG_NAME is not installed." >&2
exit $code
}
is_sudoer() {
## 定义错误代码
E_NOTROOT=87 # 非root退出错误。
## 检查是否为sudo用户
if ! $(sudo -l >/dev/null); then
echo 'Error: root privileges are needed to run this script'
return $E_NOTROOT
fi
return 0
}
if is_sudoer; then
## 删除先前的软件包版本
status="$(dpkg-query -W --showformat='${db:Status-Status}' ${PKG_NAME} 2>&1)"
if [ $? = 0 ] || [ "${status}" = installed ]; then
sudo apt remove --purge --auto-remove -y "${PKG_NAME}"
fi
pkg_path="${LOCAL_PATH}/go"
pkg_lib_path="${LIB_PATH}/go"
## 下载最新版本
[ "$BUILD" -eq "0" ] && version_build="${VERSION}" || version_build="${VERSION}.${BUILD}"
mkdir "${USER_HOME_DIR}/tmp"
cd "${USER_HOME_DIR}/tmp"
wget "${GO_URL}go${version_build}.linux-amd64.tar.gz"
## 解压并安装下载的版本
if [ -f "go${version_build}.linux-amd64.tar.gz" ]; then
sudo rm -rf "${pkg_path}" && sudo tar -xzvf "go${version_build}.linux-amd64.tar.gz" -C "${LOCAL_PATH}"
## 添加符号链接二进制文件到系统二进制和库目录
if [ ! -h "${pkg_lib_path}" ]; then
sudo ln -sv "${pkg_path}" "${pkg_lib_path}"
fi
binaries='go gofmt'
for i in $binaries; do
if [ ! -h "${BIN_PATH}/${i}" ]; then
sudo ln -sv "${pkg_lib_path}/bin/${i}" "${BIN_PATH}/${i}"
fi
done
## 测试新版本
test_package
else
echo "Error: tar file does not exits." >&2
exit 1
fi
else
exit $?
fi
- 赋予文件运行权限:
sudo chmod -v u+x ~/go-installer.sh
- 运行脚本:
./go-installer.sh
它将返回类似以下内容:
...
go/test/used.go
go/test/utf.go
go/test/varerr.go
go/test/varinit.go
go/test/winbatch.go
go/test/writebarrier.go
go/test/zerodivide.go
'/usr/lib/go' -> '/usr/local/go'
'/usr/bin/go' -> '/usr/lib/go/bin/go'
'/usr/bin/gofmt' -> '/usr/lib/go/bin/gofmt'
go version go1.19.4 linux/amd64
teocci@ubuntu:~$
- 测试您的安装:
go version
现在Go将是全局的,并且可以从任何位置运行。
英文:
This is an old question in 2022 it is almost more that 9 years. But I think it is important to automatize this installation.
Requirements:
- This was tested on Ubuntu 18 and 20.
- Sudoer user, you must be able to use
sudo
.
Installation:
- Create a new file using this command:
touch ~/go-installer.sh
- Edit the file using any of editor available i.e., vi, vim, or nano.
nano ~/go-installer.sh
- Past this script:
#!/bin/bash
## Define version and build
VERSION=1.19
BUILD=4
## Define package name
PKG_NAME='go'
## Define go official url
GO_URL='https://golang.org/dl/'
## Define local path
LOCAL_PATH='/usr/local'
## Define system library path
LIB_PATH='/usr/lib'
## Define system binary path
BIN_PATH='/usr/bin'
## Define EV script filename
EV_FILE='/etc/profile.d/go-bin-path.sh'
## Defile export path command
EXPORT_CMD='export PATH=$PATH:/usr/local/go/bin'
## Define script content
SCRIPT='#!/bin/sh\n'${EXPORT_CMD}
## Define user home dir
USER_HOME_DIR=$(getent passwd ${SUDO_USER:-$USER} | cut -d: -f6)
check_command() {
[ -x "$(command -v $PKG_NAME)" ] && echo 0 || echo 1
}
test_package() {
echo
code=$(check_command)
[ $code -eq 0 ] && go version || echo "Error: $PKG_NAME is not installed." >&2
exit $code
}
is_sudoer() {
## Define error code
E_NOTROOT=87 # Non-root exit error.
## check if is sudoer
if ! $(sudo -l &>/dev/null); then
echo 'Error: root privileges are needed to run this script'
return $E_NOTROOT
fi
return 0
}
if is_sudoer; then
## Remove previous package versions
status="$(dpkg-query -W --showformat='${db:Status-Status}' ${PKG_NAME} 2>&1)"
if [ $? = 0 ] || [ "${status}" = installed ]; then
sudo apt remove --purge --auto-remove -y "${PKG_NAME}"
fi
pkg_path="${LOCAL_PATH}/go"
pkg_lib_path="${LIB_PATH}/go"
## Download the latest version available.
[ "$BUILD" -eq "0" ] && version_build="${VERSION}" || version_build="${VERSION}.${BUILD}"
mkdir "${USER_HOME_DIR}/tmp"
cd "${USER_HOME_DIR}/tmp"
wget "${GO_URL}go${version_build}.linux-amd64.tar.gz"
## Extract and install the downloaded version
if [ -f "go${version_build}.linux-amd64.tar.gz" ]; then
sudo rm -rf "${pkg_path}" && sudo tar -xzvf "go${version_build}.linux-amd64.tar.gz" -C "${LOCAL_PATH}"
## Add symbolic link binary files to system binary and library directories
if [ ! -h "${pkg_lib_path}" ]; then
sudo ln -sv "${pkg_path}" "${pkg_lib_path}"
fi
binaries='go gofmt'
for i in $binaries; do
if [ ! -h "${BIN_PATH}/${i}" ]; then
sudo ln -sv "${pkg_lib_path}/bin/${i}" "${BIN_PATH}/${i}"
fi
done
## Test your new version.
test_package
else
echo "Error: tar file does not exits." >&2
exit 1
fi
else
exit $?
fi
- Give running permission to the file:
sudo chmod -v u+x ~/go-installer.sh
- Run the script:
./go-installer.sh
It will return something like this:
...
go/test/used.go
go/test/utf.go
go/test/varerr.go
go/test/varinit.go
go/test/winbatch.go
go/test/writebarrier.go
go/test/zerodivide.go
'/usr/lib/go' -> '/usr/local/go'
'/usr/bin/go' -> '/usr/lib/go/bin/go'
'/usr/bin/gofmt' -> '/usr/lib/go/bin/gofmt'
go version go1.19.4 linux/amd64
teocci@ubuntu:~$
- Test your installation:
go version
Now Go will be global and can run from anywhere.
答案16
得分: 0
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go
在执行上述命令并设置好Go环境之后,
如果你尝试运行一个Go程序,会显示go: no such tool "compile"
如果你遇到相同的问题,请按照下面的链接进行操作:
https://stackoverflow.com/a/76550511/22128545
英文:
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go
After above commands and go environment setup
You tried to run a go program it will show you go: no such tool "compile"
if you are facing a same then follow below link
https://stackoverflow.com/a/76550511/22128545
答案17
得分: -1
-
如果你有ubuntu-mate,你可以通过以下方式安装最新的go:
umake go
-
我有一个脚本可以从官方网站下载并安装最新的go
# 将这些变量更改为您感觉舒适的位置 DOWNLOAD_DIR=${HOME}/Downloads/GoLang INSTALL_DIR=${HOME}/App function install { mkdir -p ${DOWNLOAD_DIR} cd ${DOWNLOAD_DIR} echo "正在获取最新的Go版本..." typeset VER=`curl -s https://golang.org/dl/ | grep -m 1 -o 'go\([0-9]\)\+\(\.[0-9]\)\+'` if uname -m | grep 64 > /dev/null; then typeset ARCH=amd64 else typeset ARCH=386 fi typeset FILE=$VER.linux-$ARCH if [[ ! -e ${FILE}.tar.gz ]]; then echo "正在下载 '$FILE' ..." wget https://storage.googleapis.com/golang/${FILE}.tar.gz fi echo "正在安装 ${FILE} ..." tar zxfC ${FILE}.tar.gz ${INSTALL_DIR} echo "Go已安装" } install
设置您的GOROOT,GOPATH和PATH:
export GOROOT=${INSTALL_DIR}/go
export GOPATH=<您的go路径>
export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin
英文:
-
If you have ubuntu-mate, you can install latest go by:
umake go
-
I have a script to download and install the last go from official website
# Change these varialbe to where ever you feel comfortable DOWNLOAD_DIR=${HOME}/Downloads/GoLang INSTALL_DIR=${HOME}/App function install { mkdir -p ${DOWNLOAD_DIR} cd ${DOWNLOAD_DIR} echo "Fetching latest Go version..." typeset VER=`curl -s https://golang.org/dl/ | grep -m 1 -o 'go\([0-9]\)\+\(\.[0-9]\)\+'` if uname -m | grep 64 > /dev/null; then typeset ARCH=amd64 else typeset ARCH=386 fi typeset FILE=$VER.linux-$ARCH if [[ ! -e ${FILE}.tar.gz ]]; then echo "Downloading '$FILE' ..." wget https://storage.googleapis.com/golang/${FILE}.tar.gz fi echo "Installing ${FILE} ..." tar zxfC ${FILE}.tar.gz ${INSTALL_DIR} echo "Go is installed" } install
Setup your GOROOT, GOPATH and PATH:
export GOROOT=${INSTALL_DIR}/go
export GOPATH=<your go path>
export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin
答案18
得分: -1
你可以使用udhos/update-golang
中的脚本。
这是一个两行代码的示例(以root
用户运行):
bash <(curl -s https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh)
ln -vs /usr/local/go/bin/go* /usr/local/bin/
英文:
You can use a script from udhos/update-golang
.
Here is a two-liner as example (run as root
):
bash <(curl -s https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh)
ln -vs /usr/local/go/bin/go* /usr/local/bin/
答案19
得分: -1
在Ubuntu上安装Go的最佳方法是从这里下载所需版本。在这里,您可以找到所有稳定版本和发布版本,以及存档版本。
下载所选版本后,您可以按照以下步骤进行操作,我建议您为Ubuntu机器下载tar.gz格式:
- 首先,通过执行以下命令完全从本地删除旧版本:
sudo rm -rf /usr/local/go /usr/local/gocache
这将删除所有本地的Go代码库,但是等等,我们还需要执行其他操作以完全从本地删除,我之前忽略了这一步骤,直到我明白自己漏掉了什么,所以这是从列表中删除的清除步骤:
sudo apt-get purge golang
或者
sudo apt remove golang-go
- 现在,在终端中执行以下命令,将您下载的Go版本安装/提取到/usr/local/go目录中:
tar -C /usr/local -xzf go1.10.8.linux-amd64.tar.gz
-
在完成上述所有步骤后,请不要忘记检查或设置
GOROOT
变量的值,您可以通过go env
命令来检查该值,如果未设置,则执行export PATH=$PATH:/usr/local/go
命令。 -
最好测试一个小的Go程序以确保一切正常。如果您没有更改
GOPATH
的值,请将以下内容写入/home/yourusername/go/test.php
文件中:
package main import "fmt" func main() { fmt.Println("hello world") }
- 通过
go run test.go
命令运行该程序。
希望对您有帮助!
英文:
Best way to install Go on Ubuntu is to download required version from here. Here you could have all stable and releases, along with archived versions.
after downloading you selected version you can follow further steps, i will suggest you to download tar.gz format for ubuntu machine:
- first of all fully remove the older version from your local by doing this
sudo rm -rf /usr/local/go /usr/local/gocache
this will remove all the local go code base but wait something more we have to do to remove fully from local, i was missing this step and it took so much time until I understood what i am missing so here is the purge stuff to remove from list
> sudo apt-get purge golang
or
> sudo apt remove golang-go
- Now install / extract your downloaded version of go inside /usr/local/go, by hitting terminal with this
> tar -C /usr/local -xzf go1.10.8.linux-amd64.tar.gz
- after doing all above stuff , don't forget or check to
GOROOT
variable value you can check the value bygo env
if not set thenexport PATH=$PATH:/usr/local/go
- Better to test a small go program to make sure. write this inside
/home/yourusername/go/test.php
if you haven't changed setGOPATH
value:
> package main
>
> import "fmt"
>
> func main() {
> fmt.Println("hello world")
> }
- run this by
go run test.go
i hope it works for you!!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论