1.1 Go 安裝 Go的三種安裝方式 Go有多種安裝方式,你可以選擇自己喜歡的。這里我們介紹三種最常見的安裝方式: Go源碼安裝:這是一種標準的軟件安裝方式。對于經(jīng)常使用Unix類系統(tǒng)的用戶,尤其對于開發(fā)者來說,從源碼安裝可以自己定制。
成都創(chuàng)新互聯(lián)長期為上千客戶提供的網(wǎng)站建設服務,團隊從業(yè)經(jīng)驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為岱山企業(yè)提供專業(yè)的網(wǎng)站建設、做網(wǎng)站,岱山網(wǎng)站改版等技術服務。擁有十載豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
Linux下安裝Go開發(fā)環(huán)境操作步驟 第一步:登陸linux 第二步:用命令yum install mercurial安裝 mercurial包 第三步:用命令yum install git安裝git包 第四步:用命令yum install gcc安裝gcc
1、編譯vimgdb
下載vimgdb73和vim73
mkdir -p ./tmp
cd tmp
tar zxvf ../vim-7.3.tar.gz
unzip ../vimgdb-for-vim7.3-master.zip
mv vimgdb-for-vim7.3-master vimgdb-for-vim7.3
patch -p0 vimgdb-for-vim7.3/vim73.patch
cd vim73
安裝依賴
sudo apt-get install build-essential
sudo apt-get build-dep vim-gtk
sudo apt-get install libncurses5-dev
安裝
// 這里直接執(zhí)行make的操作
make
sudo make install
安裝vimgdb runtime
cd ../vimgdb-for-vim7.3
cp vimgdb_runtime ~/.vim/bundle
打開vim
:helptags ~/.vim/bundle/vimgdb_runtime/doc " 生成doc文件
添加配置.vimrc
" vimgdb插件
run macros/gdb_mappings.vim
在vim中執(zhí)行gdb時,報 “Unable to read from GDB pseudo tty” 的錯誤,因為沒有安裝 gdb ,所以安裝gdb
sudo apt-get install gdb
2、安裝vundle
set up vundle
$ git clone ~/.vim/bundle/vundle
Configure Plugins
在.vimrc文件的開頭添加下面的內(nèi)容,有些不是必須的,可以注掉
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)
" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'
" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
Plugin 'tpope/vim-fugitive'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from
Plugin 'L9'
Plugin 'FuzzyFinder'
" scripts not on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin ''
" ...
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" : PluginList - list configured plugins
" : PluginInstall(!) - install (update) plugins
" : PluginSearch(!) foo - search (or refresh cache first) for foo
" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Plugin commands are not allowed.
" Put your stuff after this line
Install Plugins
Launch vim and run
: PluginInstall
vim +PluginInstall +qall
3、官方vim-lang插件
Config vim file .vimrc,Add content bellow in bottom of the file
" 官方的插件
" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to
" reload them.
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
autocmd FileType go autocmd BufWritePre Fmt
4、代碼補全的插件gocode
配置go的環(huán)境變量,比如我的配置,GOPATH變量是必須要配置的,PATH中必須把GOPATH的bin也添加進去,否則沒有自動提示,會提示找不到模式
export GOROOT=/usr/local/go
export GOPATH=/data/app/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Set up gocode
Then you need to get the appropriate version of the gocode, for 6g/8g/5g compiler you can do this:
go get -u github.com/nsf/gocode (-u flag for "update")
Configure vim in .vimrc file
Plugin 'nsf/gocode', {'rtp': 'vim/'}
Install Plugins
Launch vim and run
: PluginInstall
vim +PluginInstall +qall
寫一個helloword程序,輸入fmt后按C-xC-o如果能看到函數(shù)的聲明展示出來,說明安裝是正確的。
4、代碼跳轉(zhuǎn)提示godef
Set up godef
go get -v code.google.com/p/rog-go/exp/cmd/godef
go install -v code.google.com/p/rog-go/exp/cmd/godef
git clone ~/.vim/bundle/vim-godef
Configure vim in .vimrc file
Bundle 'dgryski/vim-godef'
Install Plugins
Launch vim and run
: PluginInstall
vim +PluginInstall +qall
5、代碼結構提示gotags
Set up gotags
go get -u github.com/jstemmer/gotags
Put the following configuration in your vimrc:
Bundle 'majutsushi/tagbar'
nmap :TagbarToggle
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
命令模式下按在右邊就會顯示當前文件下的函數(shù)名,結構體名等等,光標放到相應的tag上,按回車可以快速跳到程序中的相應位置。
再次按會關閉tag窗口。
PS:本地的.vimrc的配置
" 插件管理器 vundle
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" alternatively, pass a path where Vundle should install plugins
"let path = '~/some/path/here'
"call vundle#rc(path)
" let Vundle manage Vundle, required
Plugin 'gmarik/vundle'
" The following are examples of different formats supported.
" Keep Plugin commands between here and filetype plugin indent on.
" scripts on GitHub repos
" Plugin 'tpope/vim-fugitive'
" Plugin 'Lokaltog/vim-easymotion'
" Plugin 'tpope/vim-rails.git'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
" Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" scripts from
" Plugin 'L9'
" Plugin 'FuzzyFinder'
" scripts not on GitHub
" Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
" Plugin ''
" ...
"
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
" filetype plugin on
"
" Brief help
" : PluginList - list configured plugins
" : PluginInstall(!) - install (update) plugins
" : PluginSearch(!) foo - search (or refresh cache first) for foo
" : PluginClean(!) - confirm (or auto-approve) removal of unused plugins
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Plugin commands are not allowed.
" Put your stuff after this line
syntax on
" ********************************************************************
" 這里省略了其它不相關的插件
" vimgdb插件
run macros/gdb_mappings.vim
" 官方的插件
" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to
" reload them.
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
autocmd FileType go autocmd BufWritePre buffer Fmt
" 代碼補全的插件
Bundle 'Blackrush/vim-gocode'
" 代碼跳轉(zhuǎn)提示
Bundle 'dgryski/vim-godef'
" 代碼結構提示
Bundle 'majutsushi/tagbar'
nmap F8 :TagbarToggleCR
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
具體步驟:
1、去官網(wǎng)下載go1.1.2的tarball,一般下載到tem目錄
2、打開終端cd /usr/local, tar -zxvf go1.1.2.linux-386.tar.gz
將源碼文件解壓縮到/usr/local目錄,如果解壓到其他目錄,需要自己設置GOROOT
3、安裝gcc工具,因為golang有些功能是使用c寫
sudo apt-get install bison gawk gcc libc6-dev make
4、$ cd go/src,$ ./all.bash
運行bash腳本,如果運行正常會獲得你的操作系統(tǒng)和cpu信息,自動編譯安裝
5、將export PATH=$PATH:/usr/local/go/bin 寫入$HOME/.profile
最后進行測試輸入go version 會顯示go1.1.2 linux/386
如果你有l(wèi)inux安裝盤,直接從安裝盤找到相關的安裝程序就行了,如果是rhel系列的,可以從add/remove software中找到開發(fā)相關的一些程序,比如開發(fā)工具、開發(fā)庫等,選中,安裝上就可以了。安裝后可用的是gnu下的一套開發(fā)環(huán)境,包括gcc、gnu-make等。
首先從網(wǎng)上下載go語言的編譯器,我在發(fā)布這篇經(jīng)驗的時候go語言編譯器的版本已經(jīng)更新到了1.4版。根據(jù)你的系統(tǒng)平臺下載相應的版本后,如果是壓縮文件,先解壓后雙擊運行,不是壓縮文件,直接雙擊運行就可以了,運行后出現(xiàn)下面的界面,在下面界面上單擊“Next”。
跟所有的軟件安裝包一樣,go語言編譯安裝是也需要接受許可協(xié)議,在圖中紅圈的位置單擊選擇框,同意許可協(xié)議,單擊“Next”。
在這一步你要改變go的安裝目錄,默認是安裝在C盤下,C盤下文件文件太多會影響系統(tǒng)性能,單擊紅圈所示的“change”按鈕會彈出安裝目錄選擇對話框。
在這個對話框中你選擇你要安裝go編譯器的目錄,選擇后會在紅圈所示的位置會顯示你所選擇的目錄,如果不是你預期的目錄,青重新選擇,然后單擊“OK”按鈕,對話框會回到第三步的對話框,但是目錄以及變成了你剛才選擇的目錄,這個對話框中單擊“Next”按鈕。
這一步開始安裝go編譯器了,單擊“Install”按鈕,系統(tǒng)會自動安裝go編譯器到你剛才選擇的目錄中。
如果不出意外,安裝程序開始copy文件,并以進度條的方式顯示當前的角度,一般5分鐘左右就安裝完了。
黨出現(xiàn)下面的界面的時候,表明go編譯器已經(jīng)安裝完成了。單擊“Finish”按鈕結束安裝。
安裝完后要配置一些環(huán)境變量,首先要把go安裝目錄下的bin目錄放到Path環(huán)境變量中。
接著創(chuàng)建一個GOPATH環(huán)境變量,這個變量很重要,我自己寫的代碼要放到這個變量中配置的目錄中,go編譯器才會找到并編譯
繼續(xù)在創(chuàng)建一個GOROOT變量,配合go編譯器安裝的目錄。
完成步驟后,打開命令行go verison 回車,如果配置沒有錯會出現(xiàn)go編譯器的版本信息,如下圖中紅圈所示。
網(wǎng)頁名稱:go語言怎么設置環(huán)境 配置go語言環(huán)境
文章來源:http://muchs.cn/article14/hgihge.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供、定制網(wǎng)站、網(wǎng)頁設計公司、電子商務、靜態(tài)網(wǎng)站、域名注冊
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)