postmodern / chruby Goto Github PK
View Code? Open in Web Editor NEWChanges the current Ruby
License: MIT License
Changes the current Ruby
License: MIT License
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?
Currently, chruby does not work in zsh. Some ideas:
eval $(chruby --init)
hack.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
https://github.com/postmodern/chruby/wiki/Implementing-an-'after-use'-hook
I thought some people coming from rvm might like this..
Discuss, improve upon (please! my bash-fu is kinda weak), etc if you like..
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?
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.
After selecting a ruby and then spawning a shell instance, the $GEM_ROOT
variable is lost.
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.
The idea is to use sub-commands which should help to keep the API simple (less assumptions need to be made at runtime).
$RUBIES=()
% chruby use jruby-1.7.0
% chruby use jruby
% chruby use ruby-1.9.3-p327 '-w rake'
RUBYOPT=-w rake
RBXOPT=-X19
% chruby use --system
% chruby use $(cat .ruby-version)
NOTE: zsh
/bash
users can use optional chpwd
/cd
hooks (load from share
directory)
% chruby list
% chruby help
% chruby help use
% chruby help list
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?
Do you know about ry (https://github.com/jayferd/ry)?
Since jruby still does not provide a bin/ruby
symlink, we should call ruby with an absolute path $RUBY_ROOT/bin/ruby
, so that it errors if bin/ruby
does not exist.
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?
chruby looks interesting, but I am confused on one issue. chruby lets one switch between rubies but how do these rubies get built?
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.
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
.
Environment:
Problem:
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)
I will advocate can my own testing tool for shell - https://github.com/mpapis/tf
And here is example test from rvm: https://github.com/wayneeseguin/rvm-test/blob/master/fast/use_comment_test.sh
running tests with TF is as easy as:
gem install tf
tf [--text] path/to/{test_name}_comment_test.sh
feel free to use any other tool for testing, but having tests is very useful in tool like this ;)
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.
When chruby local
is used, GEM_HOME
should be set to ~/.gem/...
using system ruby. Or perhaps call it chruby home
?
chruby-exec
isn't in the README.
Add a CONTRIBUTING.md
file which would document contributor guidelines, code-style, and contributor bootstrap info (i.e. install gpg, & shunit2).
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.
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?
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
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.
BTW:
I built an AUR package for the arch linux distribution: https://aur.archlinux.org/packages/chruby/
Refactor scripts/setup.sh
to not use ruby-build, but instead manually download, extract, compile and install every Ruby. Copy the installation instructions from the Wiki.
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.
It would be cool if one can just do:
$ ruby -v > .ruby-version
$ 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.
Consider exporting RUBY_PATCHLEVEL
, so others can display the Fully Qualified Version ($RUBY_VERSION-p$RUBY_PATCHLEVEL
).
Detect which shell the user is using and print the appropriate example configuration.
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
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.
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.
We should load RUBIES from common directories where Rubies are commonly installed.
/usr/local/rubies/
/opt/rubies/
~/.rubies/
I came across this blog post: http://devoh.com/blog/2012/07/implicit-gemsets-with-rbenv. I'm wondering if chruby can handle this kind of thing. In particular, is there something akin to ~/.rbenv/vars
?
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?
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>'
chruby won't work when starting tmux.
Steps te reproduce:
tmux
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)
?
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 ;)
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.
I set the default Ruby to use in my ~/.bash_profile
with chruby 1.9.3
. When spawning new terminals (gnome-terminal
), chruby is called a second time and somehow adds duplicate bin/
directories to PATH
.
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
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.
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.
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
How to integrate chruby and capistrano ?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.