This tutorial shows you how to install Elixir and Phoenix frameworks on a Vultr Ubuntu 16.04 server instance for development purposes.
requirements
- A new Vultr Ubuntu 16.04 server instance
- Logged in as a non-root sudo user.
Update the system:
sudo apt-get update
Install Erlang
Install Erlang using the following commands:
cd ~
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
You can check the installation:
erl
This will take you to the Erlang shell with the following output:
Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]
Eshell V10.1 (abort with ^G)
1>
Press twice CTRL+ Cto exit the Erlang shell.
Install Elixir
Install Elixir with apt-get
:
sudo apt-get install elixir
Now you can check the Elixir installation:
elixir -v
This shows the following output:
Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]
Elixir 1.7.3 (compiled with Erlang/OTP 20)
You have now installed Elixir 1.7.3 on your system.
Install Phoenix
If we have just installed Elixir for the first time, we will need to install the Hex package manager as well. Hex is required to get a Phoenix app to work and to possibly install additional dependencies.
Enter this command to install Hex:
mix local.hex
Now we can proceed with the installation of Phoenix:
mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez
Install Node.js.
Phoenix uses brunch.io to compile static assets (Javascript, CSS, and more). Therefore, you need to install Node.js.
The recommended method for installing Node.js is through nvm
(Node Version Manager).
Lead to installation nvm
we run this command:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
To find out what versions of Node.js are available to install, you can type:
nvm ls-remote
This will output:
Output
...
v8.8.1
v8.9.0 (LTS: Carbon)
v8.9.1 (LTS: Carbon)
v8.9.2 (LTS: Carbon)
v8.9.3 (LTS: Carbon)
v8.9.4 (LTS: Carbon)
v8.10.0 (LTS: Carbon)
v8.11.0 (LTS: Carbon)
v8.11.1 (LTS: Carbon)
v8.11.2 (LTS: Carbon)
v8.11.3 (LTS: Carbon)
v8.11.4 (LTS: Carbon)
-> v8.12.0 (Latest LTS: Carbon)
...
Install the version you want with the following command:
nvm install 8.12.0
Note: If you are using a different version 8.12.0
want , replace this by the version you want.
Tell me nvm
that you should use the version you just downloaded:
nvm use 8.12.0
Verify that the node was installed successfully:
node -v
Install PostgreSQL
You can easily install PostgreSQL using the apt packaging system.
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
Open the PostgreSQL shell:
sudo -u postgres psql
Change that postgres
Password in a secure password:
password postgres
After successfully changing the password, you can exit the PostgreSQL shell:
q
Restart the PostgreSQL service:
sudo systemctl restart postgresql.service
This is a Linux-only filesystem watcher that Phoenix uses to reload live code:
sudo apt-get install inotify-tools
Build a Phoenix Application
Create a new application:
mix phoenix.new ~/phoenix_project_test
If the command returns the following error:
** (Mix) The task "phx.new" could not be found
You can fix the problem with the following command:
mix archive.install https://raw.githubusercontent.com/phoenixframework/archives/master/phx_new.ez
Now run the command again to create a test phoenix app:
mix phoenix.new ~/phoenix_project_test
Change the PostgreSQL password in the configuration file with the password you set in the previous step:
nano config/dev.exs
The application will now be created successfully. Go to the application folder and start it:
cd ~/phoenix_project_test
mix ecto.create
mix phx.server
The Phoenix application is now active on the port 4000
.
–