The easiest way to install Elixir in Linux is through ASDF, period.
Using version managers is great. To be able to install multiple coexisting versions of the languages you use provides valuable DX.
Clone the GitHub repository:
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.8.1
Add some lines to your
echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.profile echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc
Make changes effective with:
source ~/.profile exec $SHELL
If we add
~/.profile instead of
~/.bashrc, it will have the side effect of allowing applications started through
dmenu —for i3 users— to be able to call ASDF installed commands.
This is because stuff in
~/.profile gets loaded when you login into your account, so anything there will be available to other programs run through
dmenu or desktop icons.
On the other hand, stuff in
~/.bashrc gets loaded everytime you open a terminal. So another way to have VSCode work with ASDF stuff would be to just start
code from the CLI.
To update to the latest stable version just type:
Let’s get some dependencies for Erlang —we need WxWidgets so we can use
sudo pacman -S unixodbc wxgtk2 # You already have in your system most of what's needed. # The full list of dependencies would be: # sudo pacman -S base-devel glu libpng libssh mesa ncurses unixodbc wxgtk2
For Ubuntu you need these dependencies:
sudo apt install build-essential autoconf m4 libncurses5-dev libwxgtk3.0-dev \ libgl1-mesa-dev libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev
Finally install Erlang and Elixir:
asdf plugin-add erlang asdf list-all erlang asdf install erlang 24.1.2 asdf global erlang 24.1.2 asdf plugin-add elixir asdf list-all elixir asdf install elixir 1.12.3-otp-24 asdf global elixir 1.12.3-otp-24
To enable the REPL history in IEx:
echo -e '\nexport ERL_AFLAGS="-kernel shell_history enabled"' >> ~/.bashrc
Let’s take on Hex the package manager now:
You can now print some info about your Elixir stack with:
You’ll see something along the lines of:
Hex: 0.21.3 Elixir: 1.12.3 OTP: 24.1.2 Built with: Elixir 1.12.3 and OTP 22.3
For completeness’ sake let’s install the latest version of Phoenix:
mix archive.install hex phx_new # Want to install a specific version? # # mix archive.install hex phx_new 1.5.7 # mix archive.install hex phx_new 1.6.0-rc.0
To create an API only app, try with this command:
mix phx.new my-app --app my_app --module MyApp --no-html
If you want to follow up on building an API using Elixir, check this out:
Building a JSON API with Phoenix and Elixir