13
11

More than 5 years have passed since last update.

Ubuntu 16.04 LTSでElixirインストール→Welcome to Phoenixするまでの手順

Last updated at Posted at 2018-08-13

Keiです。最近福岡(Twitter?)を中心にElixir界隈が賑やかになってきているようだったので、「ちょっと触るだけ...」と思って自分もUdemyでElixir+Phoenixの勉強始めてみたのですが、Elixir自体の環境構築は超絶簡単な一方、そのフレームワークであるPhoenixはPostgre SQLの導入が必要だったり(Ubuntu/Debianユーザーについては)敢えてLegacy版のNode.jsを入れる必要があったりと、サンプルアプリの動作確認までにそれなりに面倒な手順を踏む必要があったので、備忘録も兼ねて環境構築の手順をまとめておきます。

以下実行環境はUbuntu 16.04 LTSです。

|> Elixir & Erlangのインストール

ターミナルで以下のコマンドを順に打ち込めばOK。

wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i erlang-solutions_1.0_all.deb
sudo apt-get update
sudo apt-get install esl-erlang
sudo apt-get install elixir

正しくインストールされていればelixir -vでElixirのバージョンが確認でき、

elixir -v
Erlang/OTP 21 [erts-10.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]
Elixir 1.7.0 (compiled with Erlang/OTP 20)

iex でElixirのインタラクティブシェルが立ち上がります。

iex
Erlang/OTP 21 [erts-10.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [hipe]

Interactive Elixir (1.7.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 

|> Phoenixインストール→サンプルアプリ起動

同じくターミナルで以下のコマンドを順に打ちこんでください。

### 諸々インストール
mix local.hex
mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez                                        
apt-get install nodejs-legacy   # Ubuntu/Debianは普通のNodeだと動かないらしい。詳しくは→https://stackoverflow.com/questions/21168141/cannot-install-packages-using-node-package-manager-in-ubuntu    
sudo apt-get install inotify-tools
sudo apt install npm
npm install -g bower
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev

### Postgresの導入とパスワード設定
sudo apt-get install postgresql postgresql-contrib   # Postgresインストール
sudo service postgresql start   # Postgres起動

最後のコマンドでPostgresが起動するので、ひとまず初期パスワードを設定してサンプルアプリ用のDBを作成します。

--- Postgresの設定
psql (9.5.13)
Type "help" for help.

postgres=# \password postgres   
Enter new password:             --ひとまず"postgres"と入力しておく
Enter it again: 

これでCtrl+d でPostgresを出ます。
再度ターミナルで以下のコマンドを打つとローカルでWebサーバーが立ち上がるので、http://0.0.0.0:4000 にアクセスして"Welcome to Phoenix!"の画面が見れれば完了です。お疲れ様でした。

sudo -u postgres createdb mydb
mix phx.new hello  # Phoenixプロジェクト作成
#mix phx.new hello --no-ecto とすればDBを使わないプロジェクトに出来ます
mix ecto.create    # DB作成
mix phx.server     # サーバ起動

|> 参考

Elixir公式: https://elixir-lang.org/install.html#unix-and-unix-like
Phoenix公式: https://hexdocs.pm/phoenix/installation.html

13
11
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
13
11