Giter Club home page Giter Club logo

chruby's Introduction

chruby

CI

Changes the current Ruby.

Features

  • Updates $PATH.
    • Also adds RubyGems bin/ directories to $PATH.
  • Correctly sets $GEM_HOME and $GEM_PATH.
    • Users: gems are installed into ~/.gem/$ruby/$version.
    • Root: gems are installed directly into /path/to/$ruby/$gemdir.
  • Additionally sets $RUBY_ROOT, $RUBY_ENGINE, $RUBY_VERSION and $GEM_ROOT.
  • Optionally sets $RUBYOPT if second argument is given.
  • Calls hash -r to clear the command-lookup hash-table.
  • Fuzzy matching of Rubies by name.
  • Defaults to the system Ruby.
  • Optionally supports auto-switching and the .ruby-version file.
  • Supports bash and zsh.
  • Small (~100 LOC).
  • Has tests.

Anti-Features

  • Does not hook cd.
  • Does not install executable shims or require regenerating them after installing gems.
  • Does not require Rubies be installed into your home directory.
  • Does not automatically switch Rubies by default.
  • Does not require write-access to the Ruby directory in order to install gems.

Requirements

Install

wget https://github.com/postmodern/chruby/releases/download/v0.3.9/chruby-0.3.9.tar.gz
tar -xzvf chruby-0.3.9.tar.gz
cd chruby-0.3.9/
sudo make install

PGP

All releases are PGP signed for security. Instructions on how to import my PGP key can be found on my blog. To verify that a release was not tampered with:

wget https://github.com/postmodern/chruby/releases/download/v0.3.9/chruby-0.3.9.tar.gz.asc
gpg --verify chruby-0.3.9.tar.gz.asc chruby-0.3.9.tar.gz

setup.sh

chruby also includes a setup.sh script, which installs chruby. Simply run the script as root or via sudo:

sudo ./scripts/setup.sh

Homebrew

chruby can also be installed with homebrew:

brew install chruby

Or the absolute latest chruby can be installed from source:

brew install chruby --HEAD

Arch Linux

chruby is already included in the AUR:

yaourt -S chruby

Fedora Linux

chruby is available as an rpm on Fedora Copr.

FreeBSD

chruby is included in the official FreeBSD ports collection:

cd /usr/ports/devel/chruby/ && make install clean

Rubies

Manually

Chruby provides detailed instructions for installing additional Rubies:

ruby-install

You can also use ruby-install to install additional Rubies:

Installing to /opt/rubies or ~/.rubies:

ruby-install ruby
ruby-install jruby
ruby-install rubinius
ruby-install maglev

ruby-build

You can also use ruby-build to install additional Rubies:

Installing to /opt/rubies:

ruby-build 1.9.3-p392 /opt/rubies/ruby-1.9.3-p392
ruby-build jruby-1.7.3 /opt/rubies/jruby-1.7.3
ruby-build rbx-2.0.0-rc1 /opt/rubies/rubinius-2.0.0-rc1
ruby-build maglev-1.0.0 /opt/rubies/maglev-1.0.0

Configuration

Add the following to the ~/.bashrc or ~/.zshrc file:

source /usr/local/share/chruby/chruby.sh

macOS

source $HOMEBREW_PREFIX/opt/chruby/share/chruby/chruby.sh # Or run `brew info chruby` to find out installed directory

Note: macOS does not automatically execute ~/.bashrc, instead try adding to /etc/bashrc.

System Wide

If you wish to enable chruby system-wide, add the following to /etc/profile.d/chruby.sh:

if [ -n "$BASH_VERSION" ] || [ -n "$ZSH_VERSION" ]; then
  source /usr/local/share/chruby/chruby.sh
  ...
fi

This will prevent chruby from accidentally being loaded by /bin/sh, which is not always the same as /bin/bash.

Rubies

When chruby is first loaded by the shell, it will auto-detect Rubies installed in /opt/rubies/ and ~/.rubies/. After installing new Rubies, you must restart the shell before chruby can recognize them.

For Rubies installed in non-standard locations, simply append their paths to the RUBIES variable:

source /usr/local/share/chruby/chruby.sh

RUBIES+=(
  /opt/jruby-1.7.0
  "$HOME/src/rubinius"
)

Migrating

If you are migrating from another Ruby manager, set RUBIES accordingly:

RVM

RUBIES+=(~/.rvm/rubies/*)

rbenv

RUBIES+=(~/.rbenv/versions/*)

rbfu

RUBIES+=(~/.rbfu/rubies/*)

Auto-Switching

If you want chruby to auto-switch the current version of Ruby when you cd between your different projects, simply load auto.sh in ~/.bashrc or ~/.zshrc:

source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh

Note: macOS does not automatically source ~/.bashrc. Bash users should create the file ~/.bash_profile with following content:

if [[ -f ~/.profile ]]; then
    source ~/.profile
fi

if [[ $- == *i* ]] && [[ -f ~/.bashrc ]]; then
    source ~/.bashrc
fi

so that the terminal loads ~/.bashrc and ~/.profile (the POSIX one). If ~/.bash_profile exists, Bash users should append the above lines to ~/.bash_profile as needed.

chruby will check the current and parent directories for a .ruby-version file. Other Ruby switchers also understand this file: https://gist.github.com/1912050

If you want to automatically run the version of a gem executable specified in your project's Gemfile, try rubygems-bundler.

Default Ruby

Once you have loaded chruby.sh and/or auto.sh in your shell configuration, you can also set a default Ruby. Simply call the chruby function in ~/.bash_profile or ~/.zprofile:

chruby ruby-1.9

If you have enabled auto-switching, simply create a .ruby-version file:

echo "ruby-1.9" > ~/.ruby-version

RubyGems

Gems installed as a non-root user via gem install will be installed into ~/.gem/$ruby/X.Y.Z. By default, RubyGems will use the absolute path to the currently selected ruby for the shebang of any binstubs it generates. In some cases, this path may contain extra version information (e.g. ruby-2.0.0-p451). To mitigate potential problems when removing rubies, you can force RubyGems to generate binstubs with shebangs that will search for ruby in your $PATH by using gem install --env-shebang (or the equivalent short option -E). This parameter can also be added to your gemrc file.

Integration

For instructions on using chruby with other tools, please see the wiki:

Examples

List available Rubies:

$ chruby
   ruby-1.9.3-p392
   jruby-1.7.0
   rubinius-2.0.0-rc1

Select a Ruby:

$ chruby 1.9.3
$ chruby
 * ruby-1.9.3-p392
   jruby-1.7.0
   rubinius-2.0.0-rc1
$ echo $PATH
/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
$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.23
  - RUBY VERSION: 1.9.3 (2013-02-22 patchlevel 392) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/hal/.gem/ruby/1.9.3
  - RUBY EXECUTABLE: /opt/rubies/ruby-1.9.3-p392/bin/ruby
  - EXECUTABLE DIRECTORY: /home/hal/.gem/ruby/1.9.3/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-linux
  - GEM PATHS:
     - /home/hal/.gem/ruby/1.9.3
     - /opt/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "gem" => "--no-rdoc"
  - REMOTE SOURCES:
     - http://rubygems.org/

Switch to JRuby in 1.9 mode:

$ chruby jruby --1.9
$ ruby -v
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]

Switch back to system Ruby:

$ chruby system
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/hal/bin

Run a command under a Ruby with chruby-exec:

$ chruby-exec jruby -- gem update

Switch to an arbitrary Ruby on the fly:

$ chruby_use /path/to/ruby

Uninstall

  1. Remove or comment out chruby from your shell configuration.
  2. Restart your shell (ex: exec $SHELL).
  3. sudo make uninstall

Alternatives

* Deprecated in favor of chruby.

Endorsements

yeah chruby is nice, does the limited thing of switching really good, the only hope it never grows

-- Michal Papis of RVM

I just looooove chruby For the first time I'm in total control of all aspects of my Ruby installation.

-- Marius Mathiesen

Written by Postmodern, it's basically the simplest possible thing that can work.

-- Steve Klabnik

So far, I'm a huge fan. The tool does what it advertises exactly and simply. The small feature-set is also exactly and only the features I need.

-- Patrick Brisbin

I wrote ruby-version; however, chruby is already what ruby-version wanted to be. I've deprecated ruby-version in favor of chruby.

-- Wil Moore III

Credits

  • mpapis for reviewing the code.
  • havenwood for handling the homebrew formula.
  • zendeavor for style fixes.
  • #bash, #zsh, #machomebrew for answering all my questions.

chruby's People

Contributors

andrewvos avatar davidegrayson avatar egh avatar erkhembayar-gantulga avatar franklinyu avatar havenwood avatar hovsater avatar ilikepi avatar julienxx avatar kbrock avatar ku1ik avatar marcosdsanchez avatar michaelrkn avatar mpapis avatar mrkcor avatar okuramasafumi avatar postmodern avatar pushcx avatar rosstimson avatar shireeshj avatar skorfmann avatar slumos avatar spastorino avatar steveklabnik avatar swrobel avatar terotil avatar tmatilai avatar tsujigiri avatar vmrocha avatar wilmoore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chruby's Issues

Upgraded and moved Rubies, now can't load

I upgraded to the last version, but I also move my rubies from /opt/Ruby to ~/.rubies, now I get:

<internal:gem_prelude>:1:in `require': cannot load such file -- rubygems.rb (LoadError)
    from <internal:gem_prelude>:1:in `<compiled>'
<internal:gem_prelude>:1:in `require': cannot load such file -- rubygems.rb (LoadError)
    from <internal:gem_prelude>:1:in `<compiled>'

Avoid version specific path to chruby.sh in ~/.profile and others

What I got after installing:

Add chruby to ~/.bashrc or ~/.profile:

  . /usr/local/Cellar/chruby/0.2.3/share/chruby/chruby.sh

  RUBIES=(~/.rbenv/versions/*)

Binaries in Homebrew are linked into /usr/local to avoid this problem. I'm not sure if it's possible to do it for other files like chruby.sh, but if it's possible, I think it would be a good solution.

Install Guides and the FHS

I was looking at your install scripts of the wiki (e.g. https://github.com/postmodern/chruby/wiki/MRI) and I'm pretty sure they go against the FHS. Quote:

No other directories, except those listed below, may be in /usr/local after
first installing a FHS-compliant system.

See http://refspecs.linuxfoundation.org/FHS_2.3/fhs-2.3.html#USRLOCALLOCALHIERARCHY

To follow the FHS I think it would instead need to be:

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar -xzvf ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327
./configure --prefix=/usr/local/
make
sudo make install
cd ..
sudo mv ruby-1.9.3-p327 /usr/local/src/

If you want to keep the installation encapsulated, then the most appropriate location is /opt. Something like:

sudo mkdir /opt/ruby-1.9.3-p327
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz
tar -xzvf ruby-1.9.3-p327.tar.gz
cd ruby-1.9.3-p327
./configure --prefix=/opt/ruby-1.9.3-p327/
make
sudo make install
sudo mv ruby-1.9.3-p327 /opt/ruby-1.9.3-p327/src

chruby_exec() function

Would it be possible to implement a function that executes a ruby script directly from one or multiple Ruby versions? This would be come handy when writing open source Ruby libraries that should be tested against multiple Rubies.

For example:

chruby_exec <RUBIES> <COMMAND..>
chruby_exec 1.9.3,1.8.7,jruby,rbx rspec ./spec

This would then run each individual Ruby against RSpec. This would also allow for integration with automated testing tools like Guard::RSpec where it would run each test against any of the specified Rubies on save.

API Modification Proposal

Much of this is based on ideas for an API change to ruby-version; however, there are some great ideas in current chruby and in pending issues so would be happy to see chruby implement something like this.

See #29 and #30.

The idea is to use sub-commands which should help to keep the API simple (less assumptions need to be made at runtime).

configure multiple ruby directories

$RUBIES=()

change to an installed ruby

% chruby use jruby-1.7.0

change to an installed ruby (fuzzy match)

% chruby use jruby

change to an installed ruby and set options

% chruby use ruby-1.9.3-p327 '-w rake'
  • RUBYOPT=-w rake
  • RBXOPT=-X19

change to the system ruby

% chruby use --system

change to an installed ruby from file

% chruby use $(cat .ruby-version)

NOTE: zsh/bash users can use optional chpwd/cd hooks (load from share directory)

list rubies (star next to current)

% chruby list

help system

% chruby help
% chruby help use
% chruby help list

Sed

Hey man!

awesome! I'll try to use it since is very very thin an compact, I love it.

Btw I saw some sed commands, Isn't more intuitive use simples shell commands like:

${GEM_HOME/:foo:/:bar:}

Another awesome thing should be autocomplete ;)

Examples all talk about /opt

Everything says something like:

To install put this in your .zshrc:

RUBIES=(
/opt/ruby-1.9.3
)

or whatever. But it doesn't actually install them into /opt. The setup script puts them in /usr/local/, maybe that's a better example?

Write a Quickstart Guide for installing various Rubies

chruby needs a Quickstart guide for installing various Rubies. The guide should contain copy/pastable commands. The guide should also include brew/apt-get/yum commands for installing various dependencies needed to build the Rubies.

$RUBY variable conflicts with rake 10

Rake 10 (at least, I haven't checked other versions) uses ENV['RUBY'] as the location of the current ruby binary (https://github.com/jimweirich/rake/blob/master/lib/rake/file_utils.rb#L9). Whereas chruby uses it to point to the directory the current ruby sits in. This causes errors when I run rake (for example, I see "sh: /usr/local/ruby/mri-1.9.3-p194 is a directory").

I changed all references to RUBY in the chruby script to CURRENT_RUBY which got me going. I'm not submitting a patch because I expect you'll want something that looks nicer in code. I just needed to solve the problem.

no exec for sourced files

Hi there,

is there any reason why

/usr/bin/share/chruby/auto.sh
/usr/bin/share/chruby/chruby.sh

need to be executable?
I thought they are sourced by the user.

Cheers
dg

The env variable 'export' gets set by chruby

Environment:

  • zsh 5.0.1 (x86_64-apple-darwin12.2.1)
  • chruby 0.3.0 (reproduced with 464bfc2)

Problem:

  • After running chruby for the first time, the environment variable 'export' is set to the empty string.

Diagnostics:

diff -U0 <(env) <(chruby 1.9.3-p327;env)
--- /dev/fd/14  2012-12-22 02:20:52.000000000 +0100
+++ /dev/fd/15  2012-12-22 02:20:52.000000000 +0100
@@ -1 +1 @@
-PATH=/Users/pierre/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
+PATH=/Users/pierre/.gem/ruby/1.9.3/bin:/Users/pierre/.rubies/1.9.3-p327/lib/ruby/gems/1.9.1/bin:/Users/pierre/.rubies/1.9.3-p327/bin:/Users/pierre/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
@@ -28,0 +29,8 @@
+RUBY_ROOT=/Users/pierre/.rubies/1.9.3-p327
+RUBYOPT=
+RUBY_ENGINE=ruby
+RUBY_VERSION=1.9.3
+export=
+GEM_ROOT=/Users/pierre/.rubies/1.9.3-p327/lib/ruby/gems/1.9.1
+GEM_HOME=/Users/pierre/.gem/ruby/1.9.3
+GEM_PATH=/Users/pierre/.gem/ruby/1.9.3:/Users/pierre/.rubies/1.9.3-p327/lib/ruby/gems/1.9.1
zsh: exit 1     diff -U0 <(env) <(chruby 1.9.3-p327;env)

sh: /usr/local/ruby-1.9.3-p327: is a directory

When I try to run the tests for activemodel, this happens:

$ bundle exec rake test
/usr/local/ruby-1.9.3-p327 -w -I"lib:test" -I"/Users/steve/.gem/ruby/1.9.3/gems/rake-10.0.3/lib" "/Users/steve/.gem/ruby/1.9.3/gems/rake-10.0.3/lib/rake/rake_test_loader.rb" "/Users/steve/src/rails/activemodel/test/cases/attribute_methods_test.rb" "/Users/steve/src/rails/activemodel/test/cases/callbacks_test.rb" "/Users/steve/src/rails/activemodel/test/cases/conversion_test.rb" "/Users/steve/src/rails/activemodel/test/cases/deprecated_mass_assignment_security_test.rb" "/Users/steve/src/rails/activemodel/test/cases/dirty_test.rb" "/Users/steve/src/rails/activemodel/test/cases/errors_test.rb" "/Users/steve/src/rails/activemodel/test/cases/forbidden_attributes_protection_test.rb" "/Users/steve/src/rails/activemodel/test/cases/lint_test.rb" "/Users/steve/src/rails/activemodel/test/cases/model_test.rb" "/Users/steve/src/rails/activemodel/test/cases/naming_test.rb" "/Users/steve/src/rails/activemodel/test/cases/railtie_test.rb" "/Users/steve/src/rails/activemodel/test/cases/secure_password_test.rb" "/Users/steve/src/rails/activemodel/test/cases/serialization_test.rb" "/Users/steve/src/rails/activemodel/test/cases/serializers/json_serialization_test.rb" "/Users/steve/src/rails/activemodel/test/cases/serializers/xml_serialization_test.rb" "/Users/steve/src/rails/activemodel/test/cases/translation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/absence_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/acceptance_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/callbacks_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/conditional_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/confirmation_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/exclusion_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/format_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/i18n_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/inclusion_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/length_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/numericality_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/presence_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/validates_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/validations_context_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations/with_validation_test.rb" "/Users/steve/src/rails/activemodel/test/cases/validations_test.rb" 
sh: /usr/local/ruby-1.9.3-p327: is a directory
rake aborted!

Which, of course, it is! Everything outside of that seems to work though:

$ bundle exec ruby -v
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]

Ideas?

Duplicate `chruby_auto` entries in PROMPT_COMMAND

It appears that auto.sh will add duplicates of the chruby_auto function to the PROMPT_COMMAND because if there is an existing PROMPT_COMMAND it assumes that chruby_auto is not in the PROMPT_COMMAND.

It needs a check for existing chruby_auto. Something like this:

if [ -z "$(echo $PROMPT_COMMAND | grep chruby_auto)" ] ; then
  PROMPT_COMMAND="$PROMPT_COMMAND; chruby_auto"
fi

sudo and setup.rb

I have a couple ruby libraries that need to be installed the old-fashioned way, with setup.rb. But when I do so they always install to the system Ruby and not the chruby ruby. I am pretty sure the reason is b/c I have to use sudo ./setup.rb b/c my ruby is installed in /opt/Ruby/1.9.3-p327. So unless I use sudo I get a permission error. But if I use sudo, then it makes a different shell for root where chruby isn't being used.

Seems like site_ruby (and maybe vendor_ruby?) should be pointing to a local "home" just like $GEM_HOME does. But is that doable? And if not how do I work around this?

/etc/profile.d/chruby.sh graphical login issue with Ubuntu 12.04

When using scripts/setup.sh to install chruby on Ubuntu 12.04 it adds /etc/profile.d/chruby.sh after which I can no longer login on Unity (regardless of my default shell, I tried both with bash and zsh). On my system I deleted /etc/profile.d/chruby.sh and added the source command to my ~/.zshrc and am now able to login without issue and use chruby.

Proof of concept for automatic, bundler-managed gemsets

Using the same basic function as chruby_auto I created gemsets based on the Gemfile's parent directory name and replace the entire GEM environment variables with that single gem location.

Logically assuming all Gemfiles have a corresponding gemset means shim-less, bundler-managed gems.

https://github.com/daytonn/chruby/blob/automatic-gemsets/scripts/gemsets.sh

This needs tests and could be refactored into a shared function that chruby_auto could also use.

This is a proof of concept.

Thoughts?

Handling Goboliunx package manager style

I think chroot would be a perfect fit for Gobolinux style package management (also others like stow). But there is an issue. Gobolinux installs packages like so:

Programs/
  Ruby/
    1.8.7-p358/
    1.9.3-p327/
  JRuby/
    1.4.0/

And so forth. So the problem with chruby, when I set:

RUBIES=(/Programs/{Ruby,JRuby,Rubinius}/*)

Then running chruby produces:

  1.8.7-p358
  1.9.3-p327
  1.4.0

So the different implementations can't be distinguished. Note also, there may be a Current soft-link in each implementation directory pointing to which ever is the current version in use, e.g.

Programs/
  Ruby/
    1.8.7-p358/
    1.9.3-p327/
    Current -> ./1.9.3-p327

I'm moving over to this package manager so I would like to get this to work.

Add bash completion

This works for me:

__complete_chruby() {
  local cur rubie basenames
  typeset -a basenames
  cur="${COMP_WORDS[COMP_CWORD]}"
  for rubie in ${RUBIES[@]}; do
    basenames+=($(basename $rubie))
  done
  COMPREPLY=( $(compgen -W "${basenames[*]}" -- ${cur}) )
}
complete -F __complete_chruby chruby

I added it to chruby.sh, but maybe you want to do it differently to also support zsh?

Unable to list available rubies

Hello,

I'm trying to use chruby but I encountered a problem. Here how I install chruby:

$ git clone https://github.com/postmodern/chruby .chruby
$ cd .chruby
$ sudo make install
$ vim ~/.zshrc
# ...
$ exec $SHELL
$ ls ~/.rubies
2.0.0  2.0.0-dev  rbx-2.0.0
$ chruby
  *
$

Here what I have added to my .zshrc file:

. /usr/local/share/chruby/chruby.sh
RUBIES=~/.rubies/*

My problem is why chruby doesn't list .rubies directory ? I'm using Z-Shell on my computer.

Thanks. Have a nice day.

Bundler::GemNotFound

This may be similar to #79 but I'm not sure.

When I call chruby 1.9.3-p362, I immediately get:

/Library/Ruby/Gems/1.8/gems/bundler-1.2.3/lib/bundler/spec_set.rb:90:in `block in materialize': Could not find i18n-0.6.1 in any of the sources (Bundler::GemNotFound)

But chruby changes to ruby 1.9.3 just fine, all my gems are there for that ruby version, and my apps behave properly.

This could be a bundler issue, too?

Clarification

chruby looks interesting, but I am confused on one issue. chruby lets one switch between rubies but how do these rubies get built?

DOC_FILES is not set when running make install on OpenBSD

$ make install
for dir in ; do install -d /home/dentarg/local/$dir; done
for file in ; do install $file /home/dentarg/local/$file; done
install -d /home/dentarg/local/share/doc/chruby-0.2.3
cp -r  /home/dentarg/local/share/doc/chruby-0.2.3/
usage: cp [-fip] [-R [-H | -L | -P]] source target
       cp [-fip] [-R [-H | -L | -P]] source ... directory
*** Error code 1

Stop in /home/dentarg/src/chruby-0.2.3 (line 44 of Makefile).

(Yes, I changed PREFIX in the Makefile before doing make install.)

I'm not sure why this is happening. I'm on OpenBSD 5.2 and using zsh 4.3.17 (i386-unknown-openbsd5.2).

Is this the reason?

zsh:

$ find *.md *.tt *.txt 2>/dev/null
zsh: no matches found: *.tt

sh:

$ find *.md *.tt *.txt 2>/dev/null
ChangeLog.md
README.md
LICENSE.txt

I get the same result ("no matches found") when trying the find command in zsh on OS X but make install works fine. I'm confused.

Setup a website

A website would be nice. Also now that GitHub / @kneath disabled Downloads, we will need a location to store properly named releases (chruby-v0.2.3.tar.gz, not v0.2.3.tar.gz) and PGP signatures.

Newly installed ruby not listed in chruby

After successfully installed a ruby version using ruby-build, chruby does not update the installed ruby list:

$ chruby
   jruby-1.7.2
   ruby-1.8.7-p371
 * ruby-1.9.3-p362

$ ruby-build -v 2.0.0-preview2 ~/.rubies/2.0.0-preview2
...
...
Installed ruby-2.0.0-preview2 to ~/.rubies/2.0.0-preview2

$ chruby
   jruby-1.7.2
   ruby-1.8.7-p371
 * ruby-1.9.3-p362

Currently, my workaround is to reopen a new terminal to see the updated list. Does it happen to anyone else here?

Bundler not found

I've been setting up a Radiant site this week and ran into an odd issue. When I ran rake db:bootstrap it told me Bundler wasn't installed. But of course, it is and I had already run bundle install just fine. So I did a chruby system and redid it and it worked fine.

I am not sure if this is solely a Radiant issue or whether it is a broader issue stemming from Rails.

Default ruby

Should we support a default ruby? Currently users have to add chruby 1.9 to their ~/.bashrc or global config. Alternatively, users could run chruby $(cat ~/.ruby)?

zsh compatibility

Currently, chruby does not work in zsh. Some ideas:

  • The eval $(chruby --init) hack.
  • Write separate scripts for bash, zsh, etc.
  • Rewrite chruby to only use POSIX shell scripting syntax.

add a chruby-exec bin script

Add a chruby-exec bin script that would select the desired ruby, then run another command under it.

chruby-exec jruby --1.9 -- command

This would be useful for people needing to run Ruby scripts via cron jobs.

"make install" fails on Ubuntu 12.04

When attempting to install, I see this:

vagrant@ubuntu-12-04:~/chruby-0.2.2$ sudo make install
vagrant@ubuntu-12-04:~/chruby-0.2.2$ ls /usr/local/share/chruby
ls: cannot access /usr/local/share/chruby: No such file or directory

make is using sh, which doesn't like the "{etc,lib,bin,sbin,share}" shell expansion. Changing the shell to bash in the Makefile fixes it:

vagrant@ubuntu-12-04:~/chruby-0.2.2$ echo "SHELL:=/bin/bash" | cat - Makefile > Makefile.bash
vagrant@ubuntu-12-04:~/chruby-0.2.2$ sudo make -f Makefile.bash install
vagrant@ubuntu-12-04:~/chruby-0.2.2$ ls /usr/local/share/chruby
chruby.sh

I'm not sure if changing the shell is the best approach, but it works.

Errors encountered running chruby-exec in Ubuntu

In Ubuntu, /bin/sh points to dash and this seems to be the cause of the ff. errors encountered when running chruby-exec:

/usr/local/bin/chruby-exec: 10: /usr/local/bin/chruby-exec: [[: not found
/usr/local/bin/chruby-exec: 15: /usr/local/bin/chruby-exec: Syntax error: "(" unexpected

chruby problem with tmux

chruby won't work when starting tmux.

Steps te reproduce:

  1. Put a default ruby in your .zshrc or .zlogin
  2. Run tmux
  3. chruby lists your default ruby as being used, but PATH variables are not set. First you must do chruby system to unset all variables and then change back to your default version

Optionally support auto-switching

Many users have requested the ability to automatically switch to a Ruby when entering a directory which contains a .ruby-version file. While in the directory and all sub-directories, the Ruby should remain set. Only when the user ascends the directory containing the .ruby-version file should chruby switch back to system Ruby.

This feature is optional and would be enabled by loading /usr/local/share/chruby/auto.sh.

Not a git repository

Failed at make install:

[22:02][christopher@ryleh:~/Downloads/chruby-0.2.1]$ make install
fatal: Not a git repository (or any of the parent directories): .git
for dir in `find {etc,lib,bin,sbin,share} -type d 2>/dev/null`; do install -d /usr/local/$dir; done
for file in `find {etc,lib,bin,sbin,share} -type f 2>/dev/null`; do install $file /usr/local/$file; done
install -d /usr/local/share/doc/chruby-0.2.1
cp -r doc/* *.{md,tt,txt} /usr/local/share/doc/chruby-0.2.1/ 2>/dev/null || true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.