LoginSignup
7
4

More than 3 years have passed since last update.

Install Elixir and Phoenix on Ubuntu, via anyenv/erlenv/exenv/nodenv.

Last updated at Posted at 2019-08-16

Elixirのinstall方法

https://elixir-lang.jp/install.html に従いElixirをinstallできます。
Ubuntuの場合はrepoを追加してapt-get installする手順が書いてありますが、複数バージョンで試したい場合に備えてexenvでのinstallをしたいと思います。

以下の順でinstallします。

  • anyenv
  • erlenv
  • exenv
  • nodenv
  • Phonenix(via mix)

anyenvのinstall

https://github.com/anyenv/anyenv のREADMEに従ってinstall。

$ git clone https://github.com/anyenv/anyenv ~/.anyenv
$ echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.bashrc
$ ~/.anyenv/bin/anyenv init

bashrcにeval "$(anyenv init -)"を追記しようと表示されるので続ける。

$ echo 'eval "$(anyenv init -)"' >> ~/.bashrc
$ exec $SHELL -l
$ anyenv install --init

erlenvのinstall

Erlangをinstallします。

$ anyenv install erlenv
$ exec $SHELL -l

https://github.com/talentdeficit/erlenv のREADMEに従う。
erlenvはinstallコマンドが無く、自分でコンパイルする必要がある。

make時に configure: error: No curses library functions found というエラーが発生したらncursesを入れる。

$ sudo apt-get install libncurses5-dev libncursesw5-dev

Phoenixのinstall用にOpenSSLが必要となるため、libssl-devも導入する。

$ sudo apt-get install libssl-dev

odbcを入れておかないと、DBに接続できないため、unixodbc-devも導入する。

$ sudo apt-get install unixodbc-dev

よくわからないが、wxも無いと言われるので、libwxgtk3.0も導入する。

$ sudo apt-get install libwxgtk3.0

--prefix.anyenv/envs/erlenv/releases配下を指定する。
--enable-dynamic-ssl-libも指定する

$ mkdir ~/src
$ cd ~/src
$ wget http://www.erlang.org/download/otp_src_20.3.tar.gz
$ tar xzvf otp_src_20.3.tar.gz
$ cd otp_src_20.3
$ ./configure --prefix=$HOME/.anyenv/envs/erlenv/releases/22.0
*********************************************************************
**********************  APPLICATIONS DISABLED  **********************
*********************************************************************

jinterface     : No Java compiler found

*********************************************************************
*********************************************************************
**********************  DOCUMENTATION INFORMATION  ******************
*********************************************************************

documentation  : 
                 xsltproc is missing.
                 fop is missing.
                 xmllint is missing.
                 The documentation cannot be built.

*********************************************************************```

installする。

$ make
$ make install

先程installしたバージョンを指定する。

$ erlenv global 20.3
$ exec $SHELL -l

確認する。

$ erlenv global
20.3

exenvのinstall

$ anyenv install exenv
$ exec $SHELL -l

install可能なverを確認してinstall。

$ exenv install -l
$ exenv install 1.9.1
$ exenv global 1.9.1
$ exec $SHELL -l

確認する。

$ elixir -v
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

Elixir 1.9.1 (compiled with Erlang/OTP 20)

Hello World

hello.exs
defmodule Hello do
  def hi do
    IO.puts 'Hellor World!'
  end
end

Hello.hi

呼び出す。

$ elixir hello.ex 
Hellor World!

nodenvのinstall

Phonenixを起動させるために必要。
Elixirのみの導入であれば、これ以降のstepは不要。

$ anyenv install nodenv
$ exec $SHELL -l

install可能なverを確認してinstall。

$ nodenv install -l
$ nodenv install 12.8.1
$ nodenv global 12.8.1
$ exec $SHELL -l

Phoenixのinstall

https://hexdocs.pm/phoenix/installation.html のinstallationガイドを参照すると、mix local.hexで導入できる。
※もしSSLが無いよと怒られた場合は、erlenvのinstall時のconfigureのオプションを確認する。

$ mix local.hex
Are you sure you want to install "https://repo.hex.pm/installs/1.8.0/hex-0.20.1.ez"? [Yn]

Phonenixをバージョン指定でinstallする。

$ mix archive.install hex phx_new 1.4.9
Resolving Hex dependencies...
Dependency resolution completed:
New:
  phx_new 1.4.9
* Getting phx_new (Hex package)
All dependencies are up to date
Compiling 10 files (.ex)
Generated phx_new app
Generated archive "phx_new-1.4.9.ez" with MIX_ENV=prod
Are you sure you want to install "phx_new-1.4.9.ez"? [Yn]

動作確認用に、Phonenixのhelloプロジェクトを作る。

$ mix phx.new hello

成功すると、後続のステップが表示される。

We are almost there! The following steps are missing:

    $ cd hello
    $ cd assets && npm install && node node_modules/webpack/bin/webpack.js --mode development

Then configure your database in config/dev.exs and run:

    $ mix ecto.create

Start your Phoenix app with:

    $ mix phx.server

You can also run your app inside IEx (Interactive Elixir) as:

    $ iex -S mix phx.server

とりあえず動作確認。

$ cd hello
$ cd assets && npm install && node node_modules/webpack/bin/webpack.js --mode development
$ cd ..
$ mix phx.server

live-reloadできないけどoptionalだから心配ないと言われる。

[error] `inotify-tools` is needed to run `file_system` for your system, check https://github.com/rvoicilas/inotify-tools/wiki for more information about how to install it. If it's already installed but not be found, appoint executable file with `config.exs` or `FILESYSTEM_FSINOTIFY_EXECUTABLE_FILE` env.
[warn] Could not start Phoenix live-reload because we cannot listen to the file system.
You don't need to worry! This is an optional feature used during development to
refresh your browser when you save files and it does not affect production.

PostgreSQLに繋がらないと言われる。

[error] Postgrex.Protocol (#PID<0.2824.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused

ただし画面は出る。

[info] Running HelloWeb.Endpoint with cowboy 2.6.3 at 0.0.0.0:4000 (http)
[info] Access HelloWeb.Endpoint at http://localhost:4000
7
4
1

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
7
4