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
PATHfor an executable file namedelm - Find the elmenv shim named
elmat 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_VERSIONenvironment variable, if specified. You can use theelmenv shellcommand to set this environment variable in your current shell session. -
The first
.elm-versionfile 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-versionfile 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-versionfile in the current working directory with theelmenv localcommand. -
The global
~/.elmenv/versionfile. You can modify this file using theelmenv globalcommand. 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/binto your$PATHfor access to theelmenvcommand-line utility.$ echo 'export PATH="$HOME/.elmenv/bin:$PATH"' >> ~/.bash_profile
Ubuntu Desktop note: Modify your
~/.bashrcinstead of~/.bash_profile.Zsh note: Modify your
~/.zshrcfile instead of~/.bash_profile. -
Add
elmenv initto your shell to enable shims and autocompletion.$ echo 'eval "$(elmenv init -)"' >> ~/.bash_profile
Same as in previous step, use
~/.bashrcon Ubuntu, or~/.zshrcfor 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.