2
0

More than 5 years have passed since last update.

Amazon Linux に最新のdeinをインストール

Posted at

以前はVimのパッケージ管理にはNeoBundleを使っていましたが、久しぶりにLinuxを触ってみたらdeinなるものが使えるという事ですので試してみました。

環境

Amazon Linux のバージョンを確認する方法

実行結果

[ec2-user@ip-172-31-44-114 ~]$ cat /etc/system-release
Amazon Linux release 2 (Karoo)

Vimのバージョンアップ

deinのインストールは、
dein.vimでプラグイン管理の始め方
を参考に、ほばそのまま使わせて頂きましたが、異なる点は、

  • MacとLinuxの違いで、Vimの設定ファイルの位置が、~/.cofig/nvim/init.vim → ~/.vimrc
  • deinのインストールディレクトリは ~/.vim/bundles (ただ何となく、githubのreadmeの最初にあったので)
  • lazyで読み込む必要があるプラグインが(とりあえず)無かったので、dein_lazy.tomlの設定は無し
  • ひとまずdeinがインストール出来るかどうか確認するため、dein.tomlの中身は空
~/.vimrc
  1 set number
  2 set expandtab
  3 set tabstop=4
  4 set shiftwidth=4
  5 set smartindent
  6 set backspace=indent,eol,start
  7
  8 if &compatible
  9     set nocompatible
 10 endif
 11
 12 let s:dein_dir = expand('~/.vim/bundles')
 13
 14 let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'
 15
 16 if &runtimepath !~# '/dein.vim'
 17     if !isdirectory(s:dein_repo_dir)
 18         execute '!git clone https://github.com/Shougo/dein.vim' s:dein_repo_dir
 19     endif
 20     execute 'set runtimepath^=' . fnamemodify(s:dein_repo_dir, ':p')
 21 endif
 22
 23 if dein#load_state(s:dein_dir)
 24     call dein#begin(s:dein_dir)
 25     let s:toml_dir = expand('~/.vim/toml')
 26     call dein#load_toml(s:toml_dir . '/dein.toml', {'lazy': 0})
 27     call dein#end()
 28     call dein#save_state()
 29 endif
 30
 31 filetype plugin indent on
 32 syntax enable
 33
 34 if dein#check_install()
 35     dein#install()
 36 endif

上記の内容を保存し、もう一度Vimを起動すると以下のエラーが発生

[ec2-user@ip-172-31-44-114 ~]$ vi .vimrc
Error detected while processing function dein#begin..dein#util#_begin..dein#util#_error..<SNR>10_msg2list:
line    1:
E121: Undefined variable: v:t_list
E15: Invalid expression: type(a:expr) ==# v:t_list ? a:expr : split(a:expr, '\n')
Error detected while processing function dein#begin..dein#util#_begin..dein#util#_error:
line    1:
E714: List required
Error detected while processing /home/ec2-user/.vimrc:
line   31:
E492: Not an editor command: enable syntax
Press ENTER or type command to continue

エラーメッセージからググってみると:
centosのデフォルトのvimで最新のdeinを使おうとしたらハマった話
インストールしたdeinのバージョンに対して、Vimのバージョンが古すぎる、という事のようです。

[ec2-user@ip-172-31-44-114 ~]$ vim -version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jul 27 2018 06:04:47)
Garbage after option argument: "-version"
More info with: "vim -h"

上記では対応策としてdeinのバージョンを下げていますが、私はアプリケーションは出来るだけ新しいものを使う主義のため、Vimのバージョンを上げる事にしました。
CentOSでvimを7→8にバージョンアップする
足りないものはエラーになったら入れればいいやと思ったので、yum install関連の対応はとりあえずスキップ。vim.gitのクローンから始めます。
~/.vim/srcというディレクトリを作って、

git clone https://github.com/vim/vim.git

~/.vim/srcの中身はこんな感じ:

appveyor.yml  configure        Filelist  nsis     READMEdir  README.txt  src    uninstal.txt  vimtutor.com
ci            CONTRIBUTING.md  Makefile  pixmaps  README.md  runtime     tools  vimtutor.bat

ここで、

make

とすると、最初に依存性を解決するステップをスキップしているので、やはりエラーになります。

no terminal library found
checking for tgetent()... configure: error: NOT FOUND!
      You need to install a terminal library; for example ncurses.
      Or specify the name of the library with --with-tlib.
make[2]: *** [config] Error 1
make[2]: Leaving directory `/home/ec2-user/.vim/src/vim/src'
make[1]: *** [reconfig] Error 2
make[1]: Leaving directory `/home/ec2-user/.vim/src/vim/src'
make: *** [first] Error 2

develは怒られたら入れてみようという方針で、とりあえずncursesを入れて様子を見てみます:
(後記:やはり必要でした…)

[ec2-user@ip-172-31-44-114 vim]$ sudo yum install ncurses
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Package ncurses-6.0-8.20170212.amzn2.1.2.x86_64 already installed and latest version
Nothing to do

あれ?ncurses入ってるっぽい。無いと言っているのはヘッダファイル?ということで、気を取り直して、

sudo yum install ncurses-devel

今度はmake, sudo make install共にうまくいきました。(長いので、ログは割愛。)

[ec2-user@ip-172-31-44-114 vim]$ vim -version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul  7 2019 07:55:02)
Garbage after option argument: "-version"
More info with: "vim -h"

次は、本題の、Vimの起動(deinはうまく動くか?)。まずはそのまま起動してみます。

[ec2-user@ip-172-31-44-114 vim]$ vim .vimrc
[dein] Invalid toml format: /home/ec2-user/.vim/toml/dein.toml
[dein] Text.TOML: No such file `/home/ec2-user/.vim/toml/dein.toml'.
Error detected while processing /home/ec2-user/.vimrc:
line   31:
E492: Not an editor command: enable syntax
Press ENTER or type command to continue

さすがにdein.tomlが無いとダメらしい…。という事で、dein.tomlを空で作成(「無い」と「空」の違いに注意)。

[ec2-user@ip-172-31-44-114 .vim]$ touch toml/dein.toml
[ec2-user@ip-172-31-44-114 .vim]$ ls toml
dein.toml

もう一回、vim ~/.vimrcでエラーが消えた事を確認。

slimv.vimを導入

ここまで何も言わずに引っ張ってきてしまいましたが、今回deinをインストールしたのはCommon Lisp向けVimプラグインslim.vimを導入しようと思った(指が短いためEmacsは苦手)からで、他のプラグインも今後入れる事があればよしなに管理したいと思ったからなのでした。
Vimmerな人たちのためのCommonLisp構築

上記ではdeinの設定は.vimrcで行われていますが、ここでは折角dein.tomlを作ったのでtomlに設定してみます。

~/.vim/toml/dein.html
  1 [[plugins]]
  2 repo = 'Shougo/dein.vim'
  3
  4 [[plugins]]
  5 repo = 'kovisoft/slimv'

ですが、やはりエラーが…

[ec2-user@ip-172-31-44-114 .vim]$ vi toml/dein.toml
[dein] Not installed plugins: ['slimv']
Error detected while processing /home/ec2-user/.vimrc:
line   35:
E492: Not an editor command:     dein#install()
Press ENTER or type command to continue

そこで、再び
Vimmerな人たちのためのCommonLisp構築
を見返してみると

Pythonのインストール

の項目が…

pythonは一応始めから入っているようなのですが、

[ec2-user@ip-172-31-44-114 ~]$ python -V
Python 2.7.14

Vimにはpython向けの機能が入っていない模様です。

:version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul  7 2019 07:55:02)
Included patches: 1-1601
Compiled by ec2-user@ip-172-31-44-114.ap-northeast-1.compute.internal
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_any_white
+arabic            +file_in_path      +mouse_urxvt       -tcl
+autocmd           +find_in_path      +mouse_xterm       +termguicolors
+autochdir         +float             +multi_byte        +terminal
-autoservername    +folding           +multi_lang        +terminfo
-balloon_eval      -footer            -mzscheme          +termresponse
+balloon_eval_term +fork()            +netbeans_intg     +textobjects
-browse            +gettext           +num64             +textprop
++builtin_terms    -hangul_input      +packages          +timers
+byte_offset       +iconv             +path_extra        +title
+channel           +insert_expand     -perl              -toolbar
+cindent           +job               +persistent_undo   +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           -python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo

-python -python3となっています。
もしやこれが原因?

これはdeinのパッケージ管理の問題では無く、Vimのビルドパラメータの問題なので、Vimをもう一度ビルドしてやる必要がありそうです。

というより、今回、Vimをソースからビルドしているので、最初からこれを考慮に入れていれば一回の作業で済んだのですが、行き当たりばったりなので段取りが悪くてすみません…。

ついでなのでpython3を入れてみます。

sudo yum python3 install
[ec2-user@ip-172-31-44-114 ~]$ python3 -V
Python 3.7.3
[ec2-user@ip-172-31-44-114 ~]$ pip3 -V
pip 9.0.3 from /usr/lib/python3.7/site-packages (python 3.7)

python3のインストールが完了したので、

./configure --enable-python3interp > configure.log

するとconfigure.logに以下のメッセージが

checking if compile and link flags for Python 3 are sane... no: PYTHON3 DISA    BLED

エラーメッセージからググってみると、
vim初期インストール時の対応

原因1
python-devをインストールする必要がある
原因2
pythonのconfigフォルダを指定してあげる必要がある

まずは「原因1」の問題を解決してみます。

sudo yum install python3-devel

気を取り直してもう一度configureしてみます。

make distclean clean
./configure --enable-python3interp > configure.log
configure.log
 67 checking for python3... /usr/bin/python3
 68 checking Python version... 3.7
 69 checking Python is 3.0 or better... yep
 70 checking Python's abiflags... m
 71 checking Python's install prefix... /usr
 72 checking Python's execution prefix... /usr
 73 checking Python's configuration directory... /usr/lib64/python3.7/config-3.7    m-x86_64-linux-gnu
 74 checking Python3's dll name... libpython3.7m.so.1.0
 75 checking if -pthread should be used... yes
 76 checking if compile and link flags for Python 3 are sane... yes
 77 checking if -fPIE can be added for Python3... yes

今度はうまくいきました。

make
sudo make install
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 16 2019 16:09:13)
Included patches: 1-1601
Compiled by ec2-user@ip-172-31-44-114.ap-northeast-1.compute.internal
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_any_white
+arabic            +file_in_path      +mouse_urxvt       -tcl
+autocmd           +find_in_path      +mouse_xterm       +termguicolors
+autochdir         +float             +multi_byte        +terminal
-autoservername    +folding           +multi_lang        +terminfo
-balloon_eval      -footer            -mzscheme          +termresponse
+balloon_eval_term +fork()            +netbeans_intg     +textobjects
-browse            +gettext           +num64             +textprop
++builtin_terms    -hangul_input      +packages          +timers
+byte_offset       +iconv             +path_extra        +title
+channel           +insert_expand     -perl              -toolbar
+cindent           +job               +persistent_undo   +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           +python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo

Vimを起動して:

:call dein#install()
[dein] Done: (2019/07/19 14:46:31)

どうやらdeinは正常にインストールされたようです。

次に、tomlの設定により、slimvがインストールが導入されている事を確認します。

slimvSample.PNG

Common Lispのソースプログラムにシンタックスハイライトが入りました。

2
0
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
2
0