{"id":13463150,"url":"https://github.com/postmodern/chruby","last_synced_at":"2025-10-20T01:29:38.593Z","repository":{"id":4152260,"uuid":"5266284","full_name":"postmodern/chruby","owner":"postmodern","description":"Changes the current Ruby","archived":false,"fork":false,"pushed_at":"2023-04-27T11:08:46.000Z","size":637,"stargazers_count":2889,"open_issues_count":100,"forks_count":192,"subscribers_count":47,"default_branch":"master","last_synced_at":"2025-04-11T04:12:59.260Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/postmodern.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2012-08-01T23:46:08.000Z","updated_at":"2025-04-09T13:40:26.000Z","dependencies_parsed_at":"2023-07-05T18:31:57.342Z","dependency_job_id":null,"html_url":"https://github.com/postmodern/chruby","commit_stats":{"total_commits":859,"total_committers":49,"mean_commits":17.53061224489796,"dds":0.1268917345750873,"last_synced_commit":"579e3de3152b932d2bc68507cbca6f930d5bd705"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmodern%2Fchruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmodern%2Fchruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmodern%2Fchruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postmodern%2Fchruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postmodern","download_url":"https://codeload.github.com/postmodern/chruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254119472,"owners_count":22017951,"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":[],"created_at":"2024-07-31T13:00:46.965Z","updated_at":"2025-10-20T01:29:38.485Z","avatar_url":"https://github.com/postmodern.png","language":"Shell","funding_links":[],"categories":["List of \\*env-, ch\\*- and \\*vm- style version managers","Developer Tools","Shell","Web 后端","Environment Management","Tools","Ruby Version Manager","Version Managers"],"sub_categories":["Ruby Version Management","Environment management","Ruby"],"readme":"# chruby\n\n[![CI](https://github.com/postmodern/chruby/actions/workflows/shunit2.yml/badge.svg)](https://github.com/postmodern/chruby/actions/workflows/shunit2.yml)\n\nChanges the current Ruby.\n\n## Features\n\n* Updates `$PATH`.\n  * Also adds RubyGems `bin/` directories to `$PATH`.\n* Correctly sets `$GEM_HOME` and `$GEM_PATH`.\n  * Users: gems are installed into `~/.gem/$ruby/$version`.\n  * Root: gems are installed directly into `/path/to/$ruby/$gemdir`.\n* Additionally sets `$RUBY_ROOT`, `$RUBY_ENGINE`, `$RUBY_VERSION` and\n  `$GEM_ROOT`.\n* Optionally sets `$RUBYOPT` if second argument is given.\n* Calls `hash -r` to clear the command-lookup hash-table.\n* Fuzzy matching of Rubies by name.\n* Defaults to the system Ruby.\n* Optionally supports auto-switching and the `.ruby-version` file.\n* Supports [bash] and [zsh].\n* Small (~100 LOC).\n* Has tests.\n\n## Anti-Features\n\n* Does not hook `cd`.\n* Does not install executable shims or require regenerating them after\n  installing gems.\n* Does not require Rubies be installed into your home directory.\n* Does not automatically switch Rubies by default.\n* Does not require write-access to the Ruby directory in order to install gems.\n\n## Requirements\n\n* [bash] \u003e= 3 or [zsh]\n\n## Install\n\n```shell\nwget https://github.com/postmodern/chruby/releases/download/v0.3.9/chruby-0.3.9.tar.gz\ntar -xzvf chruby-0.3.9.tar.gz\ncd chruby-0.3.9/\nsudo make install\n```\n\n### PGP\n\nAll releases are [PGP] signed for security. Instructions on how to import my\nPGP key can be found on my [blog][1]. To verify that a release was not tampered \nwith:\n\n```shell\nwget https://github.com/postmodern/chruby/releases/download/v0.3.9/chruby-0.3.9.tar.gz.asc\ngpg --verify chruby-0.3.9.tar.gz.asc chruby-0.3.9.tar.gz\n```\n\n### setup.sh\n\nchruby also includes a `setup.sh` script, which installs chruby. Simply run the \nscript as root or via `sudo`:\n\n```shell\nsudo ./scripts/setup.sh\n```\n\n### Homebrew\n\nchruby can also be installed with [homebrew]:\n\n```shell\nbrew install chruby\n```\n\nOr the absolute latest chruby can be installed from source:\n\n```shell\nbrew install chruby --HEAD\n```\n\n### Arch Linux\n\nchruby is already included in the [AUR]:\n\n```shell\nyaourt -S chruby\n```\n\n### Fedora Linux\n\nchruby is available as an rpm on [Fedora Copr](https://copr.fedorainfracloud.org/coprs/postmodern/chruby/).\n    \n### FreeBSD\n\nchruby is included in the official [FreeBSD ports collection]:\n\n```shell\ncd /usr/ports/devel/chruby/ \u0026\u0026 make install clean\n```\n\n### Rubies\n\n#### Manually\n\nChruby provides detailed instructions for installing additional Rubies:\n\n* [Ruby](https://github.com/postmodern/chruby/wiki/Ruby)\n* [JRuby](https://github.com/postmodern/chruby/wiki/JRuby)\n* [Rubinius](https://github.com/postmodern/chruby/wiki/Rubinius)\n* [MagLev](https://github.com/postmodern/chruby/wiki/MagLev)\n\n#### ruby-install\n\nYou can also use [ruby-install] to install additional Rubies:\n\nInstalling to `/opt/rubies` or `~/.rubies`:\n\n```shell\nruby-install ruby\nruby-install jruby\nruby-install rubinius\nruby-install maglev\n```\n\n#### ruby-build\n\nYou can also use [ruby-build] to install additional Rubies:\n\nInstalling to `/opt/rubies`:\n\n```shell\nruby-build 1.9.3-p392 /opt/rubies/ruby-1.9.3-p392\nruby-build jruby-1.7.3 /opt/rubies/jruby-1.7.3\nruby-build rbx-2.0.0-rc1 /opt/rubies/rubinius-2.0.0-rc1\nruby-build maglev-1.0.0 /opt/rubies/maglev-1.0.0\n```\n\n## Configuration\n\nAdd the following to the `~/.bashrc` or `~/.zshrc` file:\n\n```shell\nsource /usr/local/share/chruby/chruby.sh\n```\n\n#### macOS\n\n```shell\nsource $HOMEBREW_PREFIX/opt/chruby/share/chruby/chruby.sh # Or run `brew info chruby` to find out installed directory\n```\n\n*Note:* macOS does not automatically execute `~/.bashrc`, instead try adding to `/etc/bashrc`.\n\n### System Wide\n\nIf you wish to enable chruby system-wide, add the following to\n`/etc/profile.d/chruby.sh`:\n\n```shell\nif [ -n \"$BASH_VERSION\" ] || [ -n \"$ZSH_VERSION\" ]; then\n  source /usr/local/share/chruby/chruby.sh\n  ...\nfi\n```\n\nThis will prevent chruby from accidentally being loaded by `/bin/sh`, which\nis not always the same as `/bin/bash`.\n\n### Rubies\n\nWhen chruby is first loaded by the shell, it will auto-detect Rubies installed\nin `/opt/rubies/` and `~/.rubies/`. After installing new Rubies, you _must_\nrestart the shell before chruby can recognize them.\n\nFor Rubies installed in non-standard locations, simply append their paths to\nthe `RUBIES` variable:\n\n```shell\nsource /usr/local/share/chruby/chruby.sh\n\nRUBIES+=(\n  /opt/jruby-1.7.0\n  \"$HOME/src/rubinius\"\n)\n```\n\n### Migrating\n\nIf you are migrating from another Ruby manager, set `RUBIES` accordingly:\n\n#### RVM\n\n```shell\nRUBIES+=(~/.rvm/rubies/*)\n```\n\n#### rbenv\n\n```shell\nRUBIES+=(~/.rbenv/versions/*)\n```\n\n#### rbfu\n\n```shell\nRUBIES+=(~/.rbfu/rubies/*)\n```\n\n### Auto-Switching\n\nIf you want chruby to auto-switch the current version of Ruby when you `cd`\nbetween your different projects, simply load `auto.sh` in `~/.bashrc` or\n`~/.zshrc`:\n\n```shell\nsource /usr/local/share/chruby/chruby.sh\nsource /usr/local/share/chruby/auto.sh\n```\n\n\u003e *Note:* macOS does not automatically source `~/.bashrc`. Bash users should\n\u003e create the file `~/.bash_profile` with following content:\n\u003e\n\u003e ```bash\n\u003e if [[ -f ~/.profile ]]; then\n\u003e     source ~/.profile\n\u003e fi\n\u003e\n\u003e if [[ $- == *i* ]] \u0026\u0026 [[ -f ~/.bashrc ]]; then\n\u003e     source ~/.bashrc\n\u003e fi\n\u003e ```\n\u003e\n\u003e so that the terminal loads `~/.bashrc` and `~/.profile` (the POSIX one). If\n\u003e `~/.bash_profile` exists, Bash users should append the above lines to\n\u003e `~/.bash_profile` as needed.\n\nchruby will check the current and parent directories for a [.ruby-version]\nfile. Other Ruby switchers also understand this file:\nhttps://gist.github.com/1912050\n\nIf you want to automatically run the version of a gem executable specified in \nyour project's Gemfile, try \n[rubygems-bundler](https://github.com/mpapis/rubygems-bundler).\n\n### Default Ruby\n\nOnce you have loaded `chruby.sh` and/or `auto.sh` in your shell configuration,\nyou can also set a default Ruby. Simply call the `chruby` function in\n`~/.bash_profile` or `~/.zprofile`:\n\n```shell\nchruby ruby-1.9\n```\n\nIf you have enabled auto-switching, simply create a `.ruby-version` file:\n\n```shell\necho \"ruby-1.9\" \u003e ~/.ruby-version\n```\n\n### RubyGems\n\nGems installed as a non-root user via `gem install` will be installed into\n`~/.gem/$ruby/X.Y.Z`.  By default, RubyGems will use the absolute path to the\ncurrently selected ruby for the shebang of any binstubs it generates.  In some\ncases, this path may contain extra version information (e.g.\n`ruby-2.0.0-p451`).  To mitigate potential problems when removing rubies, you\ncan force RubyGems to generate binstubs with shebangs that will search for\nruby in your `$PATH` by using `gem install --env-shebang` (or the equivalent\nshort option `-E`).  This parameter can also be added to your gemrc file.\n\n### Integration\n\nFor instructions on using chruby with other tools, please see the [wiki]:\n\n* [Capistrano](https://github.com/capistrano/chruby#readme)\n* [Chef](https://supermarket.getchef.com/cookbooks/chruby_install)\n* [Cron](https://github.com/postmodern/chruby/wiki/Cron)\n* [Emacs](https://github.com/arnebrasseur/chruby.el#readme)\n* [Pow](https://github.com/postmodern/chruby/wiki/Pow)\n* [Puppet](https://github.com/dgoodlad/puppet-chruby#readme)\n* [Sudo](https://github.com/postmodern/chruby/wiki/Sudo)\n* [Vim](https://github.com/postmodern/chruby/wiki/Vim)\n* [Fish](https://github.com/JeanMertz/chruby-fish#readme)\n\n## Examples\n\nList available Rubies:\n\n    $ chruby\n       ruby-1.9.3-p392\n       jruby-1.7.0\n       rubinius-2.0.0-rc1\n\nSelect a Ruby:\n\n    $ chruby 1.9.3\n    $ chruby\n     * ruby-1.9.3-p392\n       jruby-1.7.0\n       rubinius-2.0.0-rc1\n    $ echo $PATH\n    /home/hal/.gem/ruby/1.9.3/bin:/opt/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1/bin:/opt/rubies/ruby-1.9.3-p392/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/hal/bin:/home/hal/bin\n    $ gem env\n    RubyGems Environment:\n      - RUBYGEMS VERSION: 1.8.23\n      - RUBY VERSION: 1.9.3 (2013-02-22 patchlevel 392) [x86_64-linux]\n      - INSTALLATION DIRECTORY: /home/hal/.gem/ruby/1.9.3\n      - RUBY EXECUTABLE: /opt/rubies/ruby-1.9.3-p392/bin/ruby\n      - EXECUTABLE DIRECTORY: /home/hal/.gem/ruby/1.9.3/bin\n      - RUBYGEMS PLATFORMS:\n        - ruby\n        - x86_64-linux\n      - GEM PATHS:\n         - /home/hal/.gem/ruby/1.9.3\n         - /opt/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1\n      - GEM CONFIGURATION:\n         - :update_sources =\u003e true\n         - :verbose =\u003e true\n         - :benchmark =\u003e false\n         - :backtrace =\u003e false\n         - :bulk_threshold =\u003e 1000\n         - \"gem\" =\u003e \"--no-rdoc\"\n      - REMOTE SOURCES:\n         - http://rubygems.org/\n\nSwitch to JRuby in 1.9 mode:\n\n    $ chruby jruby --1.9\n    $ ruby -v\n    jruby 1.7.0 (1.9.3p203) 2012-10-22 ff1ebbe on OpenJDK 64-Bit Server VM 1.7.0_09-icedtea-mockbuild_2012_10_17_15_53-b00 [linux-amd64]\n\nSwitch back to system Ruby:\n\n    $ chruby system\n    $ echo $PATH\n    /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hal/bin\n\nRun a command under a Ruby with `chruby-exec`:\n\n    $ chruby-exec jruby -- gem update\n\nSwitch to an arbitrary Ruby on the fly:\n\n    $ chruby_use /path/to/ruby\n\n## Uninstall\n\n1. Remove or comment out chruby from your shell configuration.\n2. Restart your shell (ex: `exec $SHELL`).\n3. `sudo make uninstall`\n\n## Alternatives\n\n* [RVM]\n* [rbenv]\n* [rbfu]*\n* [ry]\n* [ruby-version]*\n\n\\* *Deprecated in favor of chruby.*\n\n## Endorsements\n\n\u003e yeah `chruby` is nice, does the limited thing of switching really good,\n\u003e the only hope it never grows \n\n-- [Michal Papis](https://twitter.com/mpapis/status/258049391791841280) of [RVM]\n\n\u003e I just looooove [chruby](#readme) For the first time I'm in total control of\n\u003e all aspects of my Ruby installation. \n\n-- [Marius Mathiesen](https://twitter.com/zmalltalker/status/271192206268829696)\n\n\u003e Written by Postmodern, it's basically the simplest possible thing that can\n\u003e work.\n\n-- [Steve Klabnik](http://blog.steveklabnik.com/posts/2012-12-13-getting-started-with-chruby)\n\n\u003e So far, I'm a huge fan. The tool does what it advertises exactly and simply.\n\u003e The small feature-set is also exactly and only the features I need.\n\n-- [Patrick Brisbin](http://pbrisbin.com/posts/chruby)\n\n\u003e I wrote ruby-version; however, chruby is already what ruby-version wanted to\n\u003e be. I've deprecated ruby-version in favor of chruby.\n\n-- [Wil Moore III](https://github.com/wilmoore)\n\n## Credits\n\n* [mpapis](https://github.com/mpapis) for reviewing the code.\n* [havenwood](https://github.com/havenwood) for handling the homebrew formula.\n* [zendeavor](https://github.com/zendeavor) for style fixes.\n* `#bash`, `#zsh`, `#machomebrew` for answering all my questions.\n\n[wiki]: https://github.com/postmodern/chruby/wiki\n\n[bash]: http://www.gnu.org/software/bash/\n[zsh]: http://www.zsh.org/\n[PGP]: http://en.wikipedia.org/wiki/Pretty_Good_Privacy\n[homebrew]: http://brew.sh/\n[AUR]: https://aur.archlinux.org/packages/chruby/\n[FreeBSD ports collection]: https://www.freshports.org/devel/chruby/\n[ruby-install]: https://github.com/postmodern/ruby-install#readme\n[ruby-build]: https://github.com/sstephenson/ruby-build#readme\n[.ruby-version]: https://gist.github.com/1912050\n\n[RVM]: https://rvm.io/\n[rbenv]: https://github.com/sstephenson/rbenv#readme\n[rbfu]: https://github.com/hmans/rbfu#readme\n[ry]: https://github.com/jayferd/ry#readme\n[ruby-version]: https://github.com/wilmoore/ruby-version#readme\n\n[Ruby]: http://www.ruby-lang.org/en/\n[JRuby]: http://jruby.org/\n[Rubinius]: http://rubini.us/\n\n[1]: https://postmodern.github.io/pgp/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostmodern%2Fchruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostmodern%2Fchruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostmodern%2Fchruby/lists"}