linux下搭建go環(huán)境很簡單:
1.下載go1.2.1.linux-386.tar.gz,網(wǎng)上到處有類似包,并放到linux目錄下。
taogeqq@taogeqq-virtual-machine:~/myspace$ ls
a.out go1.2.1.linux-386.tar.gz test.cpp test.go
taogeqq@taogeqq-virtual-machine:~/myspace$
2. 切換到root用戶,在root下解壓,解壓即安裝,多么綠色的軟件?。?/strong>
root@taogeqq-virtual-machine:/home/taogeqq/myspace# tar zxvf go1.2.1.linux-386.tar.gz -C /usr/local/
可以看到, 在目錄下多了go目錄:
root@taogeqq-virtual-machine:/home/taogeqq/myspace# ls /usr/local
bin etc games go include lib man sbin share src
root@taogeqq-virtual-machine:/home/taogeqq/myspace#
此時,就安裝了go環(huán)境,現(xiàn)在可以退出root用戶了
3. 寫一個test.go文件, 并測試:
taogeqq@taogeqq-virtual-machine:~/myspace$ ls
a.out go1.2.1.linux-386.tar.gz test.cpp test.go
taogeqq@taogeqq-virtual-machine:~/myspace$
taogeqq@taogeqq-virtual-machine:~/myspace$ cat test.go
package main
import "fmt"
func main(){
fmt.Println("hello world")
fmt.Println("This is my first Go code")
}
taogeqq@taogeqq-virtual-machine:~/myspace$
taogeqq@taogeqq-virtual-machine:~/myspace$ /usr/local/go/bin/go run test.go
hello world
This is my first Go code
taogeqq@taogeqq-virtual-machine:~/myspace$
獲取到了預(yù)期的結(jié)果。
有個問題, 我們執(zhí)行g(shù)o run test.go試下:
taogeqq@taogeqq-virtual-machine:~/myspace$ go run test.go
程序“go”尚未安裝。 您可以使用以下命令安裝:
sudo apt-get install golang-go
taogeqq@taogeqq-virtual-machine:~/myspace$
可見, 可以用sudo apt-get install golang-go
一件安裝, 我們之前也說過apt-get
的強(qiáng)大。
既然我們已經(jīng)安裝了, 那先可以忽略sudo apt-get install golang-go
, 那要執(zhí)行g(shù)o run test.go, 怎么辦呢? 很簡單, 把這個路徑加到PATH中就OK了, 如下:
taogeqq@taogeqq-virtual-machine:~/myspace$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
taogeqq@taogeqq-virtual-machine:~/myspace$
taogeqq@taogeqq-virtual-machine:~/myspace$ vim /home/taogeqq/.bash_profile
taogeqq@taogeqq-virtual-machine:~/myspace$
taogeqq@taogeqq-virtual-machine:~/myspace$ cat /home/taogeqq/.bash_profile
export PATH=$PATH:/usr/local/go/bin/
taogeqq@taogeqq-virtual-machine:~/myspace$
taogeqq@taogeqq-virtual-machine:~/myspace$ source /home/taogeqq/.bash_profile
taogeqq@taogeqq-virtual-machine:~/myspace$
taogeqq@taogeqq-virtual-machine:~/myspace$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/go/bin/
taogeqq@taogeqq-virtual-machine:~/myspace$
taogeqq@taogeqq-virtual-machine:~/myspace$ go run test.go
hello world
This is my first Go code
taogeqq@taogeqq-virtual-machine:~/myspace$
其中/home/taogeqq是taogeqq的主目錄。
linux下玩東西就是爽,NM的Windows注冊表,我真是煩透了。
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接