Simple management of Elm versions, inspired by projects like rbenv, nvm, and phpenv.
At a high level, elmenv intercepts Elm commands using shim
executables injected into your PATH
, determines which Elm version
has been specified by your application, and passes your commands along
to the correct Elm installation.
elmenv works by inserting a directory of shims at the front of your
PATH
:
~/.elmenv/shims:/usr/local/bin:/usr/bin:/bin
Through a process called rehashing, elmenv maintains shims in that
directory to match every Elm command across every installed version
of Elm—elm-make
, elm-reactor
, elm-package
, elm-reply
, elm
,
and so on.
Shims are lightweight executables that simply pass your command along
to elmenv. So with elmenv installed, when you run, say, elm
, your
operating system will do the following:
- Search your
PATH
for an executable file namedelm
- Find the elmenv shim named
elm
at the beginning of yourPATH
- Run the shim named
elm
, which in turn passes the command along to elmenv
When you execute a shim, elmenv determines which Elm version to use by reading it from the following sources, in this order:
-
The
ELMENV_VERSION
environment variable, if specified. You can use theelmenv shell
command to set this environment variable in your current shell session. -
The first
.elm-version
file found by searching the directory of the script you are executing and each of its parent directories until reaching the root of your filesystem. -
The first
.elm-version
file found by searching the current working directory and each of its parent directories until reaching the root of your filesystem. You can modify the.elm-version
file in the current working directory with theelmenv local
command. -
The global
~/.elmenv/version
file. You can modify this file using theelmenv global
command. If the global version file is not present, elmenv assumes you want to use the "system" Elm—i.e. whatever version would be run if elmenv weren't in your path.
This will get you going with the latest version of elmenv and make it easy to fork and contribute any changes back upstream.
-
Check out elmenv into
~/.elmenv
.$ git clone --recurse-submodules https://github.com/sonnym/elmenv.git ~/.elmenv
-
Add
~/.elmenv/bin
to your$PATH
for access to theelmenv
command-line utility.$ echo 'export PATH="$HOME/.elmenv/bin:$PATH"' >> ~/.bash_profile
Ubuntu Desktop note: Modify your
~/.bashrc
instead of~/.bash_profile
.Zsh note: Modify your
~/.zshrc
file instead of~/.bash_profile
. -
Add
elmenv init
to your shell to enable shims and autocompletion.$ echo 'eval "$(elmenv init -)"' >> ~/.bash_profile
Same as in previous step, use
~/.bashrc
on Ubuntu, or~/.zshrc
for Zsh. -
Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if elmenv was set up:
$ type elmenv #=> "elmenv is a function"
If you've installed elmenv manually using git, you can upgrade your installation to the cutting-edge version at any time.
$ cd ~/.elmenv
$ git pull
$ git submodule foreach $(git submodule update --init --recursive)
To install a Elm version for use with elmenv, run elmenv install
with the
exact name of the version you want to install. For example,
elmenv install 0.14.1
Elm versions will be installed into a directory of the same name under
~/.elmenv/versions
. It is also possible install the master
branch of
elm. The installation is directly from source, so it is necessary to have
an up to date haskell and cabal setup.