LoginSignup
26
25

More than 5 years have passed since last update.

最新versionのgolangをぶち込む方法について

Last updated at Posted at 2015-04-12

概要

Ubuntu14.10.0にgolangの最新versionをぶち込む際に困ったので、そのことについて書いていきます。
gvmというrubyでいうとrbenvのようなものを使っていきます。
(普通にsudo apt-get install golangをすると1.2.1が入るはず)

基本的にはこのサイトを翻訳しただけのものです。

gvmを入れて、golangの最新版をぶち込む

1.レポジトリーをローカルにクローンする。

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)

これによって、~/.gvmにレポジトリが作られる。

2. bashrcでgvmの設定を読み込む

[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"

これでsource ~/.bashrcをするとgvmを実行できるようになる。
ちなみに、gvmを打ってみると

$ gvm
Usage: gvm [command]

Description:
  GVM is the Go Version Manager

Commands:
  version    - print the gvm version number
  get        - gets the latest code (for debugging)
  use        - select a go version to use
  diff       - view changes to Go root
  implode    - completely remove gvm
  install    - install go versions
  uninstall  - uninstall go versions
  cross      - install go cross compilers
  linkthis   - link this directory into GOPATH
  list       - list installed go versions
  listall    - list available versions
  alias      - manage go version aliases
  pkgset     - manage go packages sets
  pkgenv     - edit the environment for a package set

となる。

rbenvと比較すると

$ rbenv
rbenv 0.4.0
Usage: rbenv <command> [<args>]

Some useful rbenv commands are:
   commands    List all available rbenv commands
   local       Set or show the local application-specific Ruby version
   global      Set or show the global Ruby version
   shell       Set or show the shell-specific Ruby version
   install     Install a Ruby version using ruby-build
   uninstall   Uninstall a specific Ruby version
   rehash      Rehash rbenv shims (run this after installing executables)
   version     Show the current Ruby version and its origin
   versions    List all Ruby versions available to rbenv
   which       Display the full path to an executable
   whence      List all Ruby versions that contain the given executable

See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/sstephenson/rbenv#readme

3. ぶち込む

rbenv install --listと同じノリで、gvm listallを打つ

#ちょっと時間かかったあとに
・・・・
   go1.3beta1
   go1.3beta2
   go1.3rc1
   go1.3rc2
   go1.4
   go1.4.1
   go1.4.2
   go1.4beta1
   go1.4rc1
   go1.4rc2
   release.r56
・・・・

と出るので、好きなのを入れる。
rbenv install 2.2.1とやるのと同じノリでgvm use go1.4.2を打つ。

4. 確認する

rbenv versionsと同じノリで、gvm listと打つと

$ gvm list
gvm gos (installed)
   go1.4.2
   system

と出るので、しっかりぶち込まれていることが確認できる。

5. 使う

rbenv global 2.2.1と同じノリでgvm use go1.4.2と打つ。

$ go version
go version go1.4.2 linux/amd64

でうまく入れられていることを確認。

6. 余談

gvm use go1.4.2

と~/.bashrcに追記しておくと、毎回ログイン時点で指定したバージョンのgoを使えるようになる。

以上。

26
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
25