{"id":13529447,"url":"https://github.com/shenv/shenv","last_synced_at":"2025-04-01T16:31:26.856Z","repository":{"id":27529291,"uuid":"114133530","full_name":"shenv/shenv","owner":"shenv","description":"Simple shell version management ","archived":false,"fork":false,"pushed_at":"2024-05-01T09:44:20.000Z","size":215,"stargazers_count":43,"open_issues_count":10,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-02T16:34:53.490Z","etag":null,"topics":["environment","management","shell","version"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shenv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-13T14:53:18.000Z","updated_at":"2024-10-20T00:18:30.000Z","dependencies_parsed_at":"2024-05-01T11:42:24.867Z","dependency_job_id":"4d432e1d-4248-48dc-83e6-045ec4d274fb","html_url":"https://github.com/shenv/shenv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenv%2Fshenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenv%2Fshenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenv%2Fshenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shenv%2Fshenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shenv","download_url":"https://codeload.github.com/shenv/shenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246670544,"owners_count":20815003,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["environment","management","shell","version"],"created_at":"2024-08-01T07:00:36.398Z","updated_at":"2025-04-01T16:31:26.173Z","avatar_url":"https://github.com/shenv.png","language":"Shell","readme":"# Simple Shell Version Management: shenv\n\n[![Join the chat at https://gitter.im/shenv/shenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/shenv/shenv?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Build Status](https://travis-ci.org/shenv/shenv.svg?branch=master)](https://travis-ci.org/shenv/shenv)\n\nshenv lets you easily switch between multiple versions of shell. It's\nsimple, unobtrusive, and follows the UNIX tradition of single-purpose\ntools that do one thing well.\n\nThis project was forked from [pyenv](https://github.com/pyenv/pyenv)\n(which itself is a fork of [rbenv](https://github.com/rbenv/rbenv))\nand modified for the shell.\n\n\n### shenv _does..._\n\n* Let you **change the global shell version** on a per-user basis.\n* Provide support for **per-project shell versions**.\n* Allow you to **override the shell version** with an environment\n  variable.\n* Search commands from **multiple versions of shell at a time**.\n\n----\n\n\n## Table of Contents\n\n* **[How It Works](#how-it-works)**\n  * [Understanding PATH](#understanding-path)\n  * [Understanding Shims](#understanding-shims)\n  * [Choosing the shell version](#choosing-the-shell-version)\n  * [Locating the shell installation](#locating-the-shell-installation)\n* **[Installation](#installation)**\n  * [Basic GitHub Checkout](#basic-github-checkout)\n    * [Upgrading](#upgrading)\n    * [Advanced Configuration](#advanced-configuration)\n    * [Uninstalling shell versions](#uninstalling-shell-versions)\n* **[Command Reference](#command-reference)**\n* **[Development](#development)**\n* **[License](#license)**\n\n\n----\n\n\n## How It Works\n\nAt a high level, shenv intercepts shell commands using shim\nexecutables injected into your `PATH`, determines which shell version\nhas been specified by your application, and passes your commands along\nto the correct shell installation.\n\n### Understanding PATH\n\nWhen you run a command like `bash` or `fish`, your operating system\nsearches through a list of directories to find an executable file with\nthat name. This list of directories lives in an environment variable\ncalled `PATH`, with each directory in the list separated by a colon:\n\n    /usr/local/bin:/usr/bin:/bin\n\nDirectories in `PATH` are searched from left to right, so a matching\nexecutable in a directory at the beginning of the list takes\nprecedence over another one at the end. In this example, the\n`/usr/local/bin` directory will be searched first, then `/usr/bin`,\nthen `/bin`.\n\n### Understanding Shims\n\nshenv works by inserting a directory of _shims_ at the front of your\n`PATH`:\n\n    $(shenv root)/shims:/usr/local/bin:/usr/bin:/bin\n\nThrough a process called _rehashing_, shenv maintains shims in that\ndirectory to match every shell command across every installed version\nof shell.\n\nShims are lightweight executables that simply pass your command along\nto shenv. So with shenv installed, when you run, say, `pip`, your\noperating system will do the following:\n\n* Search your `PATH` for an executable file named `pip`\n* Find the shenv shim named `pip` at the beginning of your `PATH`\n* Run the shim named `pip`, which in turn passes the command along to\n  shenv\n\n### Choosing the shell version\n\nWhen you execute a shim, shenv determines which shell version to use by\nreading it from the following sources, in this order:\n\n1. The `SHENV_VERSION` environment variable (if specified). You can use\n   the [`shenv shell`](https://github.com/shenv/shenv/blob/master/COMMANDS.md#shenv-shell) command to set this environment\n   variable in your current shell session.\n\n2. The application-specific `.shell-version` file in the current\n   directory (if present). You can modify the current directory's\n   `.shell-version` file with the [`shenv local`](https://github.com/shenv/shenv/blob/master/COMMANDS.md#shenv-local)\n   command.\n\n3. The first `.shell-version` file found (if any) by searching each parent\n   directory, until reaching the root of your filesystem.\n\n4. The global `$(shenv root)/version` file. You can modify this file using\n   the [`shenv global`](https://github.com/shenv/shenv/blob/master/COMMANDS.md#shenv-global) command. If the global version\n   file is not present, shenv assumes you want to use the \"system\"\n   shell. (In other words, whatever version would run if shenv weren't in your\n   `PATH`.)\n\n\n### Locating the shell installation\n\nOnce shenv has determined which version of shell your application has\nspecified, it passes the command along to the corresponding shell\ninstallation.\n\nEach shell version is installed into its own directory under\n`$(shenv root)/versions`.\n\nFor example, you might have these versions installed:\n\n* `$(shenv root)/versions/2.7.8/`\n* `$(shenv root)/versions/3.4.2/`\n* `$(shenv root)/versions/pypy-2.4.0/`\n\nAs far as shenv is concerned, version names are simply the directories in\n`$(shenv root)/versions`.\n\n### Managing Virtual Environments\n\nThere is a shenv plugin named [shenv-virtualenv](https://github.com/shenv/shenv-virtualenv) which comes with various features to help shenv users to manage virtual environments created by virtualenv or Anaconda.\nBecause the `activate` script of those virtual environments are relying on mutating `$PATH` variable of user's interactive shell, it will intercept shenv's shim style command execution hooks.\nWe'd recommend to install shenv-virtualenv as well if you have some plan to play with those virtual environments.\n\n\n----\n\n\n## Installation\n\n### Basic GitHub Checkout\n\nThis will get you going with the latest version of shenv and make it\neasy to fork and contribute any changes back upstream.\n\n1. **Check out shenv where you want it installed.**\n   A good place to choose is `$HOME/.shenv` (but you can install it somewhere else).\n\n        $ git clone https://github.com/shenv/shenv.git ~/.shenv\n\n\n2. **Define environment variable `SHENV_ROOT`** to point to the path where\n   shenv repo is cloned and add `$SHENV_ROOT/bin` to your `$PATH` for access\n   to the `shenv` command-line utility.\n\n    ```sh\n    $ echo 'export SHENV_ROOT=\"$HOME/.shenv\"' \u003e\u003e ~/.bash_profile\n    $ echo 'export PATH=\"$SHENV_ROOT/bin:$PATH\"' \u003e\u003e ~/.bash_profile\n    ```\n    **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`.  \n    **Ubuntu and Fedora note**: Modify your `~/.bashrc` file instead of `~/.bash_profile`.  \n    **Proxy note**: If you use a proxy, export `http_proxy` and `HTTPS_PROXY` too.\n\n3. **Add `shenv init` to your shell** to enable shims and autocompletion.\n   Please make sure `eval \"$(shenv init -)\"` is placed toward the end of the shell\n   configuration file since it manipulates `PATH` during the initialization.\n    ```sh\n    $ echo -e 'if command -v shenv 1\u003e/dev/null 2\u003e\u00261; then\\n  eval \"$(shenv init -)\"\\nfi' \u003e\u003e ~/.bash_profile\n    ```\n    **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`.  \n    **Ubuntu and Fedora note**: Modify your `~/.bashrc` file instead of `~/.bash_profile`.\n\n    **General warning**: There are some systems where the `BASH_ENV` variable is configured\n    to point to `.bashrc`. On such systems you should almost certainly put the abovementioned line\n    `eval \"$(shenv init -)\"` into `.bash_profile`, and **not** into `.bashrc`. Otherwise you\n    may observe strange behaviour, such as `shenv` getting into an infinite loop.\n    See [#264](https://github.com/pyenv/pyenv/issues/264) for details.\n\n4. **Restart your shell so the path changes take effect.**\n   You can now begin using shenv.\n    ```sh\n    $ exec \"$SHELL\"\n    ```\n5. **Install shell versions into `$(shenv root)/versions`.**\n   For example, to download and install Bash 4.4.12, run:\n    ```sh\n    $ shenv install bash-4.4.12\n    ```\n   **NOTE:** If you need to pass configure option to build, please use\n   `CONFIGURE_OPTS` environment variable.\n\n   **NOTE:** If you want to use proxy to download, please use `http_proxy` and `https_proxy`\n   environment variable.\n\n   **NOTE:** If you are having trouble installing a shell version,\n   please visit the wiki page about\n   [Common Build Problems](https://github.com/shenv/shenv/wiki/Common-build-problems).\n\n\n#### Upgrading\n\nIf you've installed shenv using the instructions above, you can\nupgrade your installation at any time using git.\n\nTo upgrade to the latest development version of shenv, use `git pull`:\n\n```sh\n$ cd $(shenv root)\n$ git pull\n```\n\nTo upgrade to a specific release of shenv, check out the corresponding tag:\n\n```sh\n$ cd $(shenv root)\n$ git fetch\n$ git tag\nv0.1.0\n$ git checkout v0.1.0\n```\n\n### Uninstalling shenv\n\nThe simplicity of shenv makes it easy to temporarily disable it, or\nuninstall from the system.\n\n1. To **disable** shenv managing your shell versions, simply remove the\n  `shenv init` line from your shell startup configuration. This will\n  remove shenv shims directory from PATH, and future invocations like\n  `bash` will execute the system shell version, as before shenv.\n\n  `shenv` will still be accessible on the command line, but your shell\n  apps won't be affected by version switching.\n\n2. To completely **uninstall** shenv, perform step (1) and then remove\n   its root directory. This will **delete all shell versions** that were\n   installed under `` $(shenv root)/versions/ `` directory:\n    ```sh\n    rm -rf $(shenv root)\n    ```\n   If you've installed shenv using a package manager, as a final step\n   perform the shenv package removal. For instance, for Homebrew:\n\n        brew uninstall shenv\n\n### Advanced Configuration\n\nSkip this section unless you must know what every line in your shell\nprofile is doing.\n\n`shenv init` is the only command that crosses the line of loading\nextra commands into your shell. Coming from rvm, some of you might be\nopposed to this idea. Here's what `shenv init` actually does:\n\n1. **Sets up your shims path.** This is the only requirement for shenv to\n   function properly. You can do this by hand by prepending\n   `$(shenv root)/shims` to your `$PATH`.\n\n2. **Installs autocompletion.** This is entirely optional but pretty\n   useful. Sourcing `$(shenv root)/completions/shenv.bash` will set that\n   up. There is also a `$(shenv root)/completions/shenv.zsh` for Zsh\n   users.\n\n3. **Rehashes shims.** From time to time you'll need to rebuild your\n   shim files. Doing this on init makes sure everything is up to\n   date. You can always run `shenv rehash` manually.\n\n4. **Installs the sh dispatcher.** This bit is also optional, but allows\n   shenv and plugins to change variables in your current shell, making\n   commands like `shenv shell` possible. The sh dispatcher doesn't do\n   anything crazy like override `cd` or hack your shell prompt, but if\n   for some reason you need `shenv` to be a real script rather than a\n   shell function, you can safely skip it.\n\nTo see exactly what happens under the hood for yourself, run `shenv init -`.\n\n\n### Uninstalling shell versions\n\nAs time goes on, you will accumulate shell versions in your\n`$(shenv root)/versions` directory.\n\nTo remove old shell versions, `shenv uninstall` command to automate\nthe removal process.\n\nAlternatively, simply `rm -rf` the directory of the version you want\nto remove. You can find the directory of a particular shell version\nwith the `shenv prefix` command, e.g. `shenv prefix 2.6.8`.\n\n\n----\n\n\n## Command Reference\n\nSee [COMMANDS.md](COMMANDS.md).\n\n\n----\n\n## Environment variables\n\nYou can affect how shenv operates with the following settings:\n\nname | default | description\n-----|---------|------------\n`SHENV_VERSION` | | Specifies the shell version to be used.\u003cbr\u003eAlso see [`shenv shell`](https://github.com/shenv/shenv/blob/master/COMMANDS.md#shenv-shell)\n`SHENV_ROOT` | `~/.shenv` | Defines the directory under which shell versions and shims reside.\u003cbr\u003eAlso see `shenv root`\n`SHENV_DEBUG` | | Outputs debug information.\u003cbr\u003eAlso as: `shenv --debug \u003csubcommand\u003e`\n`SHENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for shenv hooks.\n`SHENV_DIR` | `$PWD` | Directory to start searching for `.shell-version` files.\n`SHELL_BUILD_ARIA2_OPTS` | | Used to pass additional parameters to [`aria2`](https://aria2.github.io/).\u003cbr\u003eif `aria2c` binary is available on PATH, shenv use `aria2c` instead of `curl` or `wget` to download the shell Source code. If you have an unstable internet connection, you can use this variable to instruct `aria2` to accelerate the download.\u003cbr\u003eIn most cases, you will only need to use `-x 10 -k 1M` as value to `SHELL_BUILD_ARIA2_OPTS` environment variable\n\n\n\n## Development\n\nThe shenv source code is [hosted on\nGitHub](https://github.com/shenv/shenv).  It's clean, modular,\nand easy to understand, even if you're not a shell hacker.\n\nTests are executed using [Bats](https://github.com/bats-core/bats-core):\n\n    $ bats test\n    $ bats/test/\u003cfile\u003e.bats\n\nPlease feel free to submit pull requests and file bugs on the [issue\ntracker](https://github.com/shenv/shenv/issues).\n\n## License\n\nSoftware licensed under [MIT](https://opensource.org/licenses/MIT) license.\n\n[hooks]: https://github.com/shenv/shenv/wiki/Authoring-plugins#shenv-hooks\n","funding_links":[],"categories":["Shells","Shell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenv%2Fshenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshenv%2Fshenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshenv%2Fshenv/lists"}