Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

概要

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を使えるようになる。

以上。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away