搜索
首页后端开发GolangLinux怎么安装golang和dep(附错两个误解决方法)

下面由golang教程栏目给大家介绍Linux怎么安装golang和dep(附错两个误解决方法),希望对需要的朋友有所帮助!

Linux 安装 golang 和 dep (附错两个误解决方法)

安装 Go

下载

在这里找想要安装的版本: https://golang.google.cn/dl/

我下载了 1.13.7:

wget https://dl.google.com/go/go1.13.7.linux-amd64.tar.gz

解压安装

tar -C /usr/local -xzf go1.13.7.linux-amd64.tar.gz

这一步需要 root 权限,非 root 用户要加 sudo

sudo tar -C /usr/local -xzf go1.13.7.linux-amd64.tar.gz

配置环境变量

编辑 profile 文件

sudo vi /etc/profile

在文件末尾添加

export PATH=$PATH:/usr/local/go/bin

立即生效需要执行: source /etc/profile

安装 dep

方法一 通过二进制安装包安装

mkdir -p go/bin  
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

方法二 go get 安装

go get -u github.com/golang/dep/cmd/dep

方法三 直接下载

方法一、方法二都太慢了

https://github.com/golang/dep/releases/

直接到 github 的 release 页面下载,

wget https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64

下载完了添加可执行权限移动到 /usr/local/go/bin 目录下,再重命名为 dep 就好了

chmod +x dep-linux-amd64  
mv dep-linux-amd64 /usr/local/go/bin/dep

错误解决

Installation requires your GOBIN directory /root/go/bin to exist. Please create it.

按照教程直接操作是不行的

[root@zrcq7d8itgvcrhkq-1130695 ~]# curl https://raw.githubusercontent... | sh  
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  
Dload  Upload   Total   Spent    Left  Speed  
100  5230  100  5230    0     0   1982      0  0:00:02  0:00:02 --:--:--  1982  
ARCH = amd64  
OS = linux  
Installation requires your GOBIN directory /root/go/bin to exist. Please create it.

这个错误说明你没有 go/bin 目录,先执行 mkdir -p go/bin 就好了

curl: (7) Failed connect to raw.githubusercontent.com:443; Connection refused

网络问题,多试几次或者使用方法二

以上是Linux怎么安装golang和dep(附错两个误解决方法)的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:segmentfault。如有侵权,请联系admin@php.cn删除
去其他语言:比较分析去其他语言:比较分析Apr 28, 2025 am 12:17 AM

goisastrongchoiceforprojectsneedingsimplicity,绩效和引发性,butitmaylackinadvancedfeatures and ecosystemmaturity.1)

比较以其他语言的静态初始化器中的初始化功能比较以其他语言的静态初始化器中的初始化功能Apr 28, 2025 am 12:16 AM

Go'sinitfunctionandJava'sstaticinitializersbothservetosetupenvironmentsbeforethemainfunction,buttheydifferinexecutionandcontrol.Go'sinitissimpleandautomatic,suitableforbasicsetupsbutcanleadtocomplexityifoverused.Java'sstaticinitializersoffermorecontr

GO中初始功能的常见用例GO中初始功能的常见用例Apr 28, 2025 am 12:13 AM

thecommonusecasesfortheinitfunctionoare:1)加载configurationfilesbeforeThemainProgramStarts,2)初始化的globalvariables和3)runningpre-checkSorvalidationsbeforEtheprofforeTheProgrecce.TheInitFunctionIsautefunctionIsautomentycalomationalmatomatimationalycalmatemationalcalledbebeforethemainfuniinfuninfuntuntion

GO中的频道:掌握际际交流GO中的频道:掌握际际交流Apr 28, 2025 am 12:04 AM

ChannelsarecrucialingoforenablingsafeandefficityCommunicationBetnewengoroutines.theyfacilitateSynChronizationAndManageGoroutIneLifeCycle,EssentialforConcurrentProgramming.ChannelSallSallSallSallSallowSallowsAllowsEnderDendingAndReceivingValues,ActassignalsignalsforsynChronization,and actassignalsynChronization and andsupppor

包装错误:将上下文添加到错误链中包装错误:将上下文添加到错误链中Apr 28, 2025 am 12:02 AM

在Go中,可以通过errors.Wrap和errors.Unwrap方法来包装错误并添加上下文。1)使用errors包的新功能,可以在错误传播过程中添加上下文信息。2)通过fmt.Errorf和%w包装错误,帮助定位问题。3)自定义错误类型可以创建更具语义化的错误,增强错误处理的表达能力。

使用GO开发时的安全考虑使用GO开发时的安全考虑Apr 27, 2025 am 12:18 AM

Gooffersrobustfeaturesforsecurecoding,butdevelopersmustimplementsecuritybestpracticeseffectively.1)UseGo'scryptopackageforsecuredatahandling.2)Manageconcurrencywithsynchronizationprimitivestopreventraceconditions.3)SanitizeexternalinputstoavoidSQLinj

了解GO的错误接口了解GO的错误接口Apr 27, 2025 am 12:16 AM

Go的错误接口定义为typeerrorinterface{Error()string},允许任何实现Error()方法的类型被视为错误。使用步骤如下:1.基本检查和记录错误,例如iferr!=nil{log.Printf("Anerroroccurred:%v",err)return}。2.创建自定义错误类型以提供更多信息,如typeMyErrorstruct{MsgstringDetailstring}。3.使用错误包装(自Go1.13起)来添加上下文而不丢失原始错误信息,

并发程序中的错误处理并发程序中的错误处理Apr 27, 2025 am 12:13 AM

对效率的Handleerrorsinconcurrentgopragrs,UsechannelstocommunicateErrors,EmparterRorwatchers,InsterTimeouts,UsebufferedChannels和Provideclearrormessages.1)USEchannelelStopassErstopassErrorsErtopassErrorsErrorsFromGoroutInestotheStothemainfunction.2)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!