Skip to main content
  1. All Posts/

exenv

Tools Shell

This repository is archived

Simple Elixir Version Management: exenv

exenv lets you easily switch between multiple versions of Elixir. It’s
simple, unobtrusive, and follows the UNIX tradition of single-purpose
tools that do one thing well.
exenv is a Elixir version of rbenv and used denv as a reference.
Thanks to @sstephenson and @repeatedly.

exenv does…

  • Let you change the global Elixir version on a per-user basis.
  • Provide support for per-project Elixir versions.
  • Allow you to override the Elixir version with an environment
    variable.

Table of Contents

  • 1 How It Works
  • 2 Installation

    1 How It Works

    exenv operates on the per-user directory ~/.exenv. Version names in
    exenv correspond to subdirectories of ~/.exenv/versions. For
    example, you might have ~/.exenv/versions/0.6.0 and
    ~/.exenv/versions/0.7.0.
    Each version is a working tree with its own binaries, like
    ~/.exenv/versions/0.6.0/bin/elixir and
    ~/.exenv/versions/0.7.0/bin/iex. exenv makes shim binaries
    for every such binary across all installed versions of Elixir.
    These shims are simple wrapper scripts that live in ~/.exenv/shims
    and detect which Elixir version you want to use. They insert the
    directory for the selected version at the beginning of your $PATH
    and then execute the corresponding binary.
    Because of the simplicity of the shim approach, all you need to use
    exenv is ~/.exenv/shims in your $PATH.

    2 Installation

    2.1 Basic GitHub Checkout

    This will get you going with the latest version of exenv and make it
    easy to fork and contribute any changes back upstream.

    1. Check out exenv into ~/.exenv.

       $ cd
       $ git clone git://github.com/mururu/exenv.git .exenv
      
    2. Add ~/.exenv/bin to your $PATH for access to the exenv
      command-line utility.

       $ echo 'export PATH="$HOME/.exenv/bin:$PATH"' >> ~/.bash_profile
      
      <p>
        <strong>Zsh note</strong>: Modify your <code>~/.zshenv</code> file instead of <code>~/.bash_profile</code>. </li> 
        
        <li>
          Add exenv init to your shell to enable shims and autocompletion.</p> <pre class="notranslate"><code> $ echo 'eval "$(exenv init -)"' &gt;&gt; ~/.bash_profile
      

          <p>
            <strong>Zsh note</strong>: Modify your <code>~/.zshenv</code> file instead of <code>~/.bash_profile</code>. </li> 
            
            <li>
              Restart your shell so the path changes take effect. You can now<br /> begin using exenv.</p> <pre class="notranslate"><code> $ exec $SHELL
      

    3.       <li>
              Install Elixir versions into <code>~/.exenv/versions</code>. For example, to<br /> install Elixir 0.13.3, download and unpack the source, then run:</p> <pre class="notranslate"><code> $ wget https://github.com/elixir-lang/elixir/archive/v0.13.3.zip
      

      $ unzip v0.13.3.zip $ mv elixir-0.13.3/ ~/.exenv/versions/0.13.3

            <li>
              Rebuild the shim binaries. You should do this any time you install<br /> a new Elixir binary (for example, when installing a new Elixir version,<br /> or when installing a gem that provides a binary).</p> <pre class="notranslate"><code> $ exenv rehash
      

          <h4 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--211-upgrading" class="anchor" aria-hidden="true" href="#-211-upgrading"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_2.1.1"></a> 2.1.1 Upgrading
          </h4>
          
          <p>
            If you&#8217;ve installed exenv using the instructions above, you can<br /> upgrade your installation at any time using git.<br /> To upgrade to the latest development version of exenv, use <code>git pull</code>:
          </p>
          
          <pre class="notranslate"><code>$ cd ~/.exenv
    

    $ git pull

          <p>
            To upgrade to a specific release of exenv, check out the corresponding<br /> tag:
          </p>
          
          <pre class="notranslate"><code>$ cd ~/.exenv
    

    $ git fetch $ git tag v0.1.0 v0.1.1 v0.1.2 v0.2.0 $ git checkout v0.2.0

          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--22-neckbeard-configuration" class="anchor" aria-hidden="true" href="#-22-neckbeard-configuration"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_2.2"></a> 2.2 Neckbeard Configuration
          </h3>
          
          <p>
            Skip this section unless you must know what every line in your shell<br /> profile is doing.<br /> <code>exenv init</code> is the only command that crosses the line of loading<br /> extra commands into your shell. Coming from rvm, some of you might be<br /> opposed to this idea. Here&#8217;s what <code>exenv init</code> actually does:
          </p>
          
          <ol dir="auto">
            <li>
              Sets up your shims path. This is the only requirement for exenv to<br /> function properly. You can do this by hand by prepending<br /> <code>~/.exenv/shims</code> to your <code>$PATH</code>.
            </li>
            <li>
              Installs autocompletion. This is entirely optional but pretty<br /> useful. Sourcing <code>~/.exenv/completions/exenv.bash</code> will set that<br /> up. There is also a <code>~/.exenv/completions/exenv.zsh</code> for Zsh<br /> users.
            </li>
            <li>
              Rehashes shims. From time to time you&#8217;ll need to rebuild your<br /> shim files. Doing this on init makes sure everything is up to<br /> date. You can always run <code>exenv rehash</code> manually.
            </li>
            <li>
              Installs the sh dispatcher. This bit is also optional, but allows<br /> exenv and plugins to change variables in your current shell, making<br /> commands like <code>exenv shell</code> possible. The sh dispatcher doesn&#8217;t do<br /> anything crazy like override <code>cd</code> or hack your shell prompt, but if<br /> for some reason you need <code>exenv</code> to be a real script rather than a<br /> shell function, you can safely skip it.
            </li>
          </ol>
          
          <p>
            Run <code>exenv init -</code> for yourself to see exactly what happens under the<br /> hood.
          </p>
          
          <h2 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--3-usage" class="anchor" aria-hidden="true" href="#-3-usage"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_3"></a> 3 Usage
          </h2>
          
          <p>
            Like <code>git</code>, the <code>exenv</code> command delegates to subcommands based on its<br /> first argument. The most common subcommands are:
          </p>
          
          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--31-exenv-global" class="anchor" aria-hidden="true" href="#-31-exenv-global"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_3.1"></a> 3.1 exenv global
          </h3>
          
          <p>
            Sets the global version of Elixir to be used in all shells by writing<br /> the version name to the <code>~/.exenv/version</code> file. This version can be<br /> overridden by a per-project <code>.exenv-version</code> file, or by setting the<br /> <code>EXENV_VERSION</code> environment variable.
          </p>
          
          <pre class="notranslate"><code>$ exenv global 0.7.0
    

          <p>
            The special version name <code>system</code> tells exenv to use the system Elixir<br /> (detected by searching your <code>$PATH</code>).<br /> When run without a version number, <code>exenv global</code> reports the<br /> currently configured global version.
          </p>
          
          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--32-exenv-local" class="anchor" aria-hidden="true" href="#-32-exenv-local"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_3.2"></a> 3.2 exenv local
          </h3>
          
          <p>
            Sets a local per-project Elixir version by writing the version name to<br /> an <code>.exenv-version</code> file in the current directory. This version<br /> overrides the global, and can be overridden itself by setting the<br /> <code>EXENV_VERSION</code> environment variable or with the <code>exenv shell</code><br /> command.
          </p>
          
          <pre class="notranslate"><code>$ exenv local 0.6.0
    

          <p>
            When run without a version number, <code>exenv local</code> reports the currently<br /> configured local version. You can also unset the local version:
          </p>
          
          <pre class="notranslate"><code>$ exenv local --unset
    

          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--33-exenv-shell" class="anchor" aria-hidden="true" href="#-33-exenv-shell"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_3.3"></a> 3.3 exenv shell
          </h3>
          
          <p>
            Sets a shell-specific Elixir version by setting the <code>EXENV_VERSION</code><br /> environment variable in your shell. This version overrides both<br /> project-specific versions and the global version.
          </p>
          
          <pre class="notranslate"><code>$ exenv shell 0.7.0
    

          <p>
            When run without a version number, <code>exenv shell</code> reports the current<br /> value of <code>EXENV_VERSION</code>. You can also unset the shell version:
          </p>
          
          <pre class="notranslate"><code>$ exenv shell --unset
    

          <p>
            Note that you&#8217;ll need exenv&#8217;s shell integration enabled (step 3 of<br /> the installation instructions) in order to use this command. If you<br /> prefer not to use shell integration, you may simply set the<br /> <code>EXENV_VERSION</code> variable yourself:
          </p>
          
          <pre class="notranslate"><code>$ export EXENV_VERSION=0.6.0
    

          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--34-exenv-versions" class="anchor" aria-hidden="true" href="#-34-exenv-versions"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_3.4"></a> 3.4 exenv versions
          </h3>
          
          <p>
            Lists all Elixir versions known to exenv, and shows an asterisk next to<br /> the currently active version.
          </p>
          
          <pre class="notranslate"><code>$ exenv versions
    

    0.5.0

    • 0.6.0 0.7.0

          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--35-exenv-version" class="anchor" aria-hidden="true" href="#-35-exenv-version"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_3.5"></a> 3.5 exenv version
          </h3>
      
          <p>
            Displays the currently active Elixir version, along with information on<br /> how it was set.
          </p>
      
          <pre class="notranslate"><code>$ exenv version
      

    0.7.0 (set by /Volumes/37signals/basecamp/.exenv-version)

          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--36-exenv-rehash" class="anchor" aria-hidden="true" href="#-36-exenv-rehash"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_3.6"></a> 3.6 exenv rehash
          </h3>
          
          <p>
            Installs shims for all Elixir binaries known to exenv (i.e.,<br /> <code>~/.exenv/versions/*/bin/*</code>). Run this command after you install a new<br /> version of Elixir.
          </p>
          
          <pre class="notranslate"><code>$ exenv rehash
    

          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--37-exenv-which" class="anchor" aria-hidden="true" href="#-37-exenv-which"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_3.7"></a> 3.7 exenv which
          </h3>
          
          <p>
            Displays the full path to the binary that exenv will execute when you<br /> run the given command.
          </p>
          
          <pre class="notranslate"><code>$ exenv which iex
    

    /Users/sam/.exenv/versions/0.7.0/bin/iex

          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--38-exenv-install" class="anchor" aria-hidden="true" href="#-38-exenv-install"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_3.8"></a> 3.8 exenv install
          </h3>
          
          <p>
            Using elixir-build,<br /> you can install Elixir automatically. Please see here(elixir-build)<br /> for more details.
          </p>
          
          <h2 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--4-development" class="anchor" aria-hidden="true" href="#-4-development"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_4"></a> 4 Development
          </h2>
          
          <p>
            The exenv source code is hosted on<br /> GitHub. It&#8217;s clean, modular,<br /> and easy to understand, even if you&#8217;re not a shell hacker.<br /> Please feel free to submit pull requests and file bugs on the issue<br /> tracker.
          </p>
          
          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--41-version-history" class="anchor" aria-hidden="true" href="#-41-version-history"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_4.1"></a> 4.1 Version History
          </h3>
          
          <p>
            <strong>0.1.0</strong> (November 10, 2012)<br /> Fork rbenv
          </p>
          
          <h3 dir="auto">
            <a rel="nofollow noopener" target="_blank" id="user-content--42-license" class="anchor" aria-hidden="true" href="#-42-license"></a><a rel="nofollow noopener" target="_blank" name="user-content-section_4.2"></a> 4.2 License
          </h3>
          
          <p>
            (The MIT license)<br /> Copyright (c) 2011 Sam Stephenson, Yuki Ito<br /> Permission is hereby granted, free of charge, to any person obtaining<br /> a copy of this software and associated documentation files (the<br /> &#8220;Software&#8221;), to deal in the Software without restriction, including<br /> without limitation the rights to use, copy, modify, merge, publish,<br /> distribute, sublicense, and/or sell copies of the Software, and to<br /> permit persons to whom the Software is furnished to do so, subject to<br /> the following conditions:<br /> The above copyright notice and this permission notice shall be<br /> included in all copies or substantial portions of the Software.<br /> THE&#8230;
          </p>