はじめに
go使うための環境構築メモです。EC2で自分が環境構築したときのログをメモとして残しておきます。
zshのインストール
いきなりですがgoと関係ないですw
zshに慣れていこうと思い、ついでにインストールして使うようにしてます。
・sudo apt-get update
・sudo apt-get install zsh
・zshと入力後に2をえらぶ
・which zshでパス確認
・sudo chsh ubuntuで上のパスをいれる
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
ubuntu@MyEC2:~$ sudo apt-get install zsh Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-aws-headers-4.15.0-1023 linux-aws-headers-4.15.0-1027 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: zsh-common Suggested packages: zsh-doc The following NEW packages will be installed: zsh zsh-common 0 upgraded, 2 newly installed, 0 to remove and 90 not upgraded. Need to get 4066 kB of archives. After this operation, 15.2 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 zsh-common all 5.4.2-3ubuntu3.1 [3376 kB] Get:2 http://ap-northeast-1.ec2.archive.ubuntu.com/ubuntu bionic-updates/main amd64 zsh amd64 5.4.2-3ubuntu3.1 [690 kB] Fetched 4066 kB in 1s (7263 kB/s) Selecting previously unselected package zsh-common. (Reading database ... 148220 files and directories currently installed.) Preparing to unpack .../zsh-common_5.4.2-3ubuntu3.1_all.deb ... Unpacking zsh-common (5.4.2-3ubuntu3.1) ... Selecting previously unselected package zsh. Preparing to unpack .../zsh_5.4.2-3ubuntu3.1_amd64.deb ... Unpacking zsh (5.4.2-3ubuntu3.1) ... Setting up zsh-common (5.4.2-3ubuntu3.1) ... Processing triggers for man-db (2.8.3-2) ... Setting up zsh (5.4.2-3ubuntu3.1) ... ubuntu@MyEC2:~$ zsh This is the Z Shell configuration function for new users, zsh-newuser-install. You are seeing this message because you have no zsh startup files (the files .zshenv, .zprofile, .zshrc, .zlogin in the directory ~). This function can help you with a few settings that should make your use of the shell easier. You can: (q) Quit and do nothing. The function will be run again next time. (0) Exit, creating the file ~/.zshrc containing just a comment. That will prevent this function being run again. (1) Continue to the main menu. (2) Populate your ~/.zshrc with the configuration recommended by the system administrator and exit (you will need to edit the file by hand, if so desired). --- Type one of the keys in parentheses --- 2 /home/ubuntu/.zshrc:15: scalar parameter HISTFILE created globally in function zsh-newuser-install ubuntu@MyEC2 ~ % which zsh /usr/bin/zsh ubuntu@MyEC2 ~ % sudo chsh ubuntu Changing the login shell for ubuntu Enter the new value, or press ENTER for the default Login Shell [/bin/bash]: /usr/bin/zsh ubuntu@MyEC2 ~ % |
teratermだとマウスでスクロールできなくなってしまうのでTERATERM.INIの
TranslateWheelToCursor=onを
TranslateWheelToCursor=offに変更する。
goのインストール
こちらを参照しながら実施。
以下のリンクからgo.linux.amd64.tar.gzのリンクをコピー。
ここではgo1.11.4.linux-amd64.tar.gzとします。
wget https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.11.4.linux-amd64.tar.gz
vim $HOME/.zshrcで以下を追記
1 2 |
export GOPATH=$HOME/go export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin |
その後source $HOME/.zshrcでOK
go versionで確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
ubuntu@MyEC2 ~ % wget https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz --2019-01-05 12:05:34-- https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz Resolving dl.google.com (dl.google.com)... 172.217.26.46, 2404:6800:4004:800::200e Connecting to dl.google.com (dl.google.com)|172.217.26.46|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 126643341 (121M) [application/octet-stream] Saving to: ‘go1.11.4.linux-amd64.tar.gz’ go1.11.4.linux-amd64.tar.gz 100%[=================================================>] 120.78M 40.6MB/s in 3.0s 2019-01-05 12:05:37 (40.6 MB/s) - ‘go1.11.4.linux-amd64.tar.gz’ saved [126643341/126643341] ubuntu@MyEC2 ~ % sudo tar -C /usr/local -xzf go1.11.4.linux-amd64.tar.gz ubuntu@MyEC2 ~ % vim $HOME/.zshrc ubuntu@MyEC2 ~ % source $HOME/.zshrc ubuntu@MyEC2 ~ % ubuntu@MyEC2 ~ % go version go version go1.11.4 linux/amd64 ubuntu@MyEC2 ~ % |
vim-goのインストール
vimでgoのコードを書くのでvimをカスタマイズします。
まず以下2つのコマンドを実行。
1 2 |
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim git clone https://github.com/fatih/vim-go.git ~/.vim/plugged/vim-go |
以下コマンドで.vimrcを編集。いまのところ使っている自分の設定が↓です。
vim ~/.vimrc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
call plug#begin() Plug 'fatih/vim-go' Plug 'fatih/molokai' Plug 'SirVer/ultisnips' Plug 'nathanaelkane/vim-indent-guides' call plug#end() "Plug 'fatih/vim-go' let g:go_version_warning = 0 let g:go_fmt_autosave = 0 "Plug 'fatih/molokai' let g:go_highlight_functions = 1 let g:go_highlight_methods = 1 let g:go_highlight_structs = 1 let g:rehash256 = 1 let g:molokai_original = 1 colorscheme molokai "Plug 'nathanaelkane/vim-indent-guides' let g:UltiSnipsExpandTrigger="<tab>" let g:UltiSnipsJumpForwardTrigger="<tab>" let g:UltiSnipsJumpBackwardTrigger="<s-tab>" "Plug 'nathanaelkane/vim-indent-guides' let g:indent_guides_enable_on_vim_startup = 1 |
最後にvim起動して:PlugInstallと入力してenterで完了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
ubuntu@MyEC2 ~ % curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 74434 100 74434 0 0 257k 0 --:--:-- --:--:-- --:--:-- 257k ubuntu@MyEC2 ~ % ubuntu@MyEC2 ~ % git clone https://github.com/fatih/vim-go.git ~/.vim/plugged/vim-go Cloning into '/home/ubuntu/.vim/plugged/vim-go'... remote: Enumerating objects: 1, done. remote: Counting objects: 100% (1/1), done. remote: Total 11635 (delta 0), reused 0 (delta 0), pack-reused 11634 Receiving objects: 100% (11635/11635), 4.00 MiB | 3.31 MiB/s, done. Resolving deltas: 100% (6878/6878), done. ubuntu@MyEC2 ~ % |
最後に
なんでdocker使わなかったんだろう?w
ま、まあいいやw
そ、そのうちdockerにする可能性も無きにしも非ず。
コメント