linux go 安装 卸载 1.15.7
linux go 环境安装1,Linux go 下载2,Linux go 安装3,配置环境4,测试go1,Linux go 下载安装系统╰─➤lsb_release -aNo LSB modules are available.Distributor ID: KaliDescription:Kali GNU/Linux RollingRelease:2...
·
linux go 环境安装
1,Linux go 下载
- 安装系统
╰─➤ lsb_release -a
No LSB modules are available.
Distributor ID: Kali
Description: Kali GNU/Linux Rolling
Release: 2019.2
Codename: n/a
- go官网下载界面(右键安装包,复制链接地址)
go1.12.7.linux-amd64.tar.gz Archive Linux x86-64 122MB 66d83bfb5a9ede000e33c6579a91a29e6b101829ad41fffb5c5bb6c900e109d9
curl -O https://dl.google.com/go/go1.12.7.linux-amd64.tar.gz
# sha256sum go1.12.7.linux-amd64.tar.gz
66d83bfb5a9ede000e33c6579a91a29e6b101829ad41fffb5c5bb6c900e109d9 go1.12.7.linux-amd64.tar.gz
1.1 go 国内下载
wget https://studygolang.com/dl/golang/go1.15.7.linux-amd64.tar.gz
2,Linux go 安装
# tar -zxvf go1.12.7.linux-amd64.tar.gz
# ls -lh
drwxr-xr-x 10 root root 4.0K Jul 8 21:29 go
# chown -R root:root ./go
drwxr-xr-x 10 root root 4.0K Jul 8 21:29 go
# mv go /usr/local/
- 或者
tar -C /usr/local/ -zxvf go1.14.4.linux-amd64.tar.gz
3,配置环境
# vim ~/.profile
# cat ~/.profile
export GOPATH=$HOME/work
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
# source ~/.profile
3.1 GOPATH 默认为当前用户目录下go目录
# go env GOPATH
/root/go
- 环境变量可以设置为
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
# source .profile
# go version
go version go1.15.7 linux/amd64
4,测试go
# go version
go version go1.7.4 linux/amd64
# mkdir -p $HOME/work/src
# pwd
/root/work/src/
# touch hello.go
cat hello.go
package main
import "fmt"
func main() {
fmt.Printf("Hello, World!\n")
}
# go build hello.go
# go run hello.go
Hello, World!
# ls -lh
总用量 2.0M
-rwxr-xr-x 1 root root 2.0M 7月 9 22:15 hello
-rw-r--r-- 1 root root 83 7月 9 21:42 hello.go
# ./hello
Hello, World!
# touch hello.go
cat hello.go
package main
import "fmt"
func main() {
fmt.Printf("Hello, World!\n")
}
# go build hello.go
# go run hello.go
Hello, World!
# ls -lh
总用量 2.0M
-rwxr-xr-x 1 root root 2.0M 7月 9 22:15 hello
-rw-r--r-- 1 root root 83 7月 9 21:42 hello.go
# ./hello
Hello, World!
卸载go
- 查看安装
# which go
/usr/bin/go
# cd /usr/local/
# ls -l | grep go
drwxr-xr-x 10 root root 4096 10月 18 06:02 go
# cd /usr/bin/
# ls -l | grep go
lrwxrwxrwx 1 root root 21 9月 5 03:03 go -> ../lib/go-1.13/bin/go
lrwxrwxrwx 1 root root 24 9月 5 03:03 gofmt -> ../lib/go-1.13/bin/gofmt
- 卸载
rm -rf /usr/local/go /usr/bin/go /usr/bin/gofmt
# rm -rf /usr/local/go
# rm -rf /usr/bin/go
# rm -rf /usr/bin/gofmt
- 安装
# tar -zxvf go1.13.3.linux-amd64.tar.gz -C /usr/local
# ln -s /usr/local/go/bin/* /usr/bin/
# go version
go version go1.13.3 linux/amd64
5,go1.14.4
tar -C /usr/local/ -zxvf go1.14.4.linux-amd64.tar.gz
vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
source /etc/profile
# which go
/usr/local/go/bin/go
# go version
go version go1.14.4 linux/amd64
# go env
GOPATH="/root/go"
GOROOT="/usr/local/go"
6,go设置国内代理
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GO111MODULE=on
7,go 1.15.7
tar -C /usr/local/ -zxvf go1.15.7.linux-amd64.tar.gz
vim ~/.profile
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
# source .profile
# go version
go version go1.15.7 linux/amd64
参考:
更多推荐
已为社区贡献12条内容
所有评论(0)