Upgrading Git Bash to run newly downloaded ruby 2.0.0 - ruby

I'm on a Windows machine, so unfortunately I can't use RVM, which would make this super easy.
I previously downloaded Rails and Ruby on a new Windows machine. Rails 4.0.3 and Ruby 1.9.3. For some reason, the package I installed didn't install the new version of ruby. So I just went to http://rubyinstaller.org/downloads/ and downloaded Ruby 2.0.0. If I browse to my Apps to access the Start Command Prompt with Ruby, the version is 2.0.0 (ruby -v). But I use Git Bash, http://git-scm.com/downloads, as my Command Line. Right now, the current ruby version is still 1.9.3 in my Git Bash window. How do I update it to use the newly downloaded Ruby 2.0.0???
Thanks for the help.

Issuing
$ which ruby
will tell you which of the two ruby executables GIT Bash wants to use.
For situations where it is necessary to have two versions of Ruby, it's possible to select one or other for general use using the PATH environment variable.
The order of paths in the Bash $PATH environment variable is important - if the path for your ruby 1.9.3 executable appears before the path for your ruby 2.0.0 executable, then the interpreter will use the 1.9.3. So, for example;
Ruby 1.9.3 is in /c/Software/Ruby/1.9.3/ruby.exe
Ruby 2.0.0 is in /c/Program Files/Ruby/2.0.0/ruby.exe
And your PATH variable is as follows;
$ echo $PATH
/c/GIT/bin:.:/c/Software/Ruby/1.9.3/:/c/Program Files/Ruby/2.0.0/
Then you would need to re-order your PATH variable so that the 2.0.0 path comes before the 1.9.3 path. Find your .bashrc file (by default in your home directory) and examine any PATH definitions, e.g.;
PATH=$PATH:/c/Program Files/Ruby/2.0.0/
And modify so that your 2.0.0 path has precedence
PATH=/c/Program Files/Ruby/2.0.0/:$PATH
You can issue this command on the command line also, making sure to do
$ export $PATH
once you've made your changes. Otherwise you'll need to source .bashrc or start a new shell. GIT Bash should then pick up the correct executable.
An alternative is to create aliases or symbolic links for each executable which specifies their version, such that typing ;
$ ruby193
Executes the 1.9.3 ruby and
$ ruby200
executes the 2.0.0 version.
Aliasing is as follows;
$ alias ruby193=/c/Software/Ruby/1.9.3/ruby.exe
Linking is as follows;
$ ln -s /c/Software/Ruby/1.9.3/ruby.exe /c/GIT/bin/ruby193
Aliases you use frequently should be put in .bashrc .

Related

/usr/bin/env: ruby: No such file or directory

I use Ubuntu 14.04 and I have installed ruby with rbenv months ago. Everything was working fine but I believed I messed with $PATH doing other stuff and now it says /usr/bin/env: ruby: No such file or directory every time I try to use a command related to ruby.
rbenv versions
2.2.3
echo $PATH
/home/rafael/.rbenv/shims:/home/rafael/.rbenv/bin:/home/rafael/.rbenv/shims:/home/rafael/.rbenv/bin:/home/rafael/.rbenv/shims:/home/rafael/.rbenv/bin:/usr/local/heroku/bin:/home/rafael/.rbenv/plugins/ruby-build/bin:/home/rafael/.rbenv/shims:/home/rafael/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/rafael/.rvm/bin:/home/rafael/.rvm/bin
It is possible to find ruby 2.2.3 inside rbenv versions but it is like it is not installed. I am thinking of deleting everything and reinstall ruby. But I want to believe that there is a simpler solution that I am not seeing. Help, please.
It's one of 2 things
The path that crontab uses doesn't have your Ruby in it. This is usually because the "safe" path that cron uses doesn't include /usr/local/bin
Cron isn't finding the rbenv paths on the server.
You can set the path explicitly in your crontab and see if that fixes it in either case.

How to load the RVM part of user's .bashrc to run Ruby CGI scripts under Apache?

I've configured a new server on Ubuntu 12.04 and I started to use RVM.
I've installed RVM under my user (as myself, not as root with sudo) by following the Ryan Bigg's guide, with no previous system-wide installed Ruby. So, I didn't have any Ruby under /usr/bin. My first task then was to replace the shebang line of all my CGI scripts, from
!#/usr/bin/ruby
to
!#/usr/bin/env ruby
However my scripts didn't run under Apache. In the terminal I could run them (by typing ./index.cgi, for example), but not over a browser. A relevant note: in both the user is the same, i.e., the Apache user is the same as the one logged on terminal. Through php tests, I've checked the RVM enviroment (last lines of .bashrc) was not loaded under Apache.
I saw this tip for running CGI scripts with RVM, which suggests to put the complete path of specific version of Ruby in the shebang line. That can be useful if you have scripts which run on different versions of Ruby. But that solution doesn't work for me, because my scripts must run on different machines, with different users and different paths.
The solution which works for me is to put a symlink of the desired Ruby version under /usr/bin:
sudo ln -s /home/apache_user/.rvm/rubies/ruby-1.8.7-p370/bin/ruby /usr/bin/ruby
But I want to know if there's a better solution, because I guess that rvm --default use is better than sudo ln -s.
I am thinking about:
loading the RVM Environment on startup (but I don't know how to achieve that);
loading the RVM Environment for each web request (which can degrade performance, and I don't know how to configure Apache to do that);
maybe the RVM Environment is loaded and all I must do is to guess the name of relevant variables to pass with PassEnv directive. But I doubt that. (Why Apache would run the .bashrc instead of another shell like csh or ksh?)
you can source the ruby environment, I'm not sure if it's enough to source it in $HOME for apache or if you need to modify /etc/init.d/apache2, but the line is:
source /path/to/rvm/environments/<name>
where for <name> you can either use full ruby name or an alias name
You can create aliases with:
rvm alias create veve 1.9.3-p125#my-project
which for RVM installed in /home/app/.rvm will allow you to use:
source /home/app/.rvm/environments/veve
in .bashrc or /etc/init.d/apache2 (just near top, bellow shebang).
you could always do
sudo ln -s /usr/local/rvm/rubies/default/bin/ruby /usr/bin/ruby
That will link the default version of the rvm-managed Ruby to /usr/bin/ruby and you will never have to do anything. set it and forget it.

How do I specify the order of "default" rvms?

I have RVM installed, with project rvmrc files enabled.
In my bashrc I have:
rvm use 1.9.2
However, in one of my project rvmrc files I have:
rvm use 1.8.7
Which works great, however if I open up a new terminal window within the project I get:
Using /home/.../.rvm/gems/ruby-1.8.7-p352
Using /home/.../.rvm/gems/ruby-1.9.2-p290
Obviously, I want to 1.8.7, but the bashrc gets run after the project rvmrc. Meaning I'm using the wrong rvm so either have to cd out and back into the directory or run rvm use 1.8.7 again.
Is there anyway to force the rvmrc file to run after the bashrc?
I know about rvm default, but not sure if I want to\can use this.
please read this: https://rvm.beginrescueend.com/support/faq/#shell_login it describes which files should be used in which use cases.
as for rvm --default 1.9.2 it should be used over manually entering version into your rc file as it is loading ruby only if one was not yet selected.
Simplest solution for your rc files problem (I guess you have one) would be rvm get head --auto which will reorganize sourcing rvm in your rc files - to make it fully functional you need to restart your graphical session (or just reboot computer).

How to get Pik running in Git/Cygwin after it gets running in Command prompt of Windows XP?

I have Installed Ruby 1.8.7. Now I want to have Ruby 1.9.2 as well on my system.Having a windows system I have to go for PIK instead of RVm. I have already in place Cygwin and Git Bash. I now have installed pik through windows XP command prompt and changed the $PATH variable putting the pik path before ruby path. Now pik commands work sin windows but do not allow me to install new Ruby as throws anerror "1.9.2 is unknown". My Cygwin and Git gets the ruby version right but do not recognize pik common and I am not sure how to get it done. From other article i changed the the USER PROFILE variable in one of the bash files of Cygwin and also Git and tried but to no help.
I need your help in telling me exactly which file i need to put that common and in $USERPROFILE directory i could not locate any bash file and all my installation are on C drive.

How does MacPorts install packages? How can I activate a Ruby installation done via MacPorts?

After trying to install ruby19 on my machine (PPC, Mac OSX 10.5.7) using the following commandline
sudo port install ruby19
the version of ruby didn't change
ruby -v => ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
I assume that i have two versions of it installed on my mac, but how do i use the latest one now?
By default, the Ruby 1.9 port in MacPorts installs the Ruby binary in /opt/local/bin/ruby1.9. It appends a 1.9 to avoid stomping on Ruby 1.8.7 libraries and gems, since not all gems are compatible with 1.9 yet. So you have to launch Ruby 1.9 with ruby1.9 (and irb1.9, etc.)
If you don't want to have to do this, you have two options:
Alias ruby to ruby1.9 in your shell config file.
Install the Ruby 1.9 port with the +nosuffix variant. Be warned, however, that if you have installed Ruby 1.8 via MacPorts, installing Ruby 1.9 via MacPorts without the 1.9 suffix may cause conflicts (with gems, etc.).
To use a specific ruby version if you have two versions installed you can either specify an absolute path to the one you want. E.g. /your/path/to/ruby Or you can change your PATH setting in your .profile
you can type
which ruby
to see the path to the ruby executable that is used at the moment.
using
echo $PATH
You can see the current PATH setting. You have to prepend the path to your new ruby binary to the PATH so that it will be found before the other one.
As ayaz already mentions, the default location of your macports stuff is in /opt/local. If you add /opt/local/bin in front of your path it should be fine. (Make sure to start a new terminal window after the change - they will not be picked up in your current session unless you explicitely 'source' the .profile file again)
One note of caution: after prepending /opt/local/bin to your path the shell will always prefer binaries in there to binaries found later, this can be an issue if you depend on specific versions in /bin, /sbin or /usr/sbin -- depending on your situation this means that you should not do it (if your computer is processing sensitive data and/or in a bank or something) or just have to remember that it could be an issue (if your computer is a normal development machine).
See http://www.tech-recipes.com/rx/2621/os_x_change_path_environment_variable/ if you need some more hints on how to set your PATH on osx.
Just a quick clarification about MacPorts. Ayaz is right that, by default, MacPorts will install things in /opt/local. (This makes it easy to globally uninstall later, if you want, and it keeps MacPorts packages out of the way of OS X packages.)
When you install MacPorts, it will normally edit your $PATH (and your $MANPATH) for you by updating your user's .profile (creating it, if it doesn't already exist).
As a precaution, the installer will create a backup of the original .profile in case you want to roll back the changes (or if you completely uninstall MacPorts later). Here's an example from a random machine at work.
admin ~ $ ls .profile*
.profile .profile.macports-saved_2009-08-03_at_14:55:56
If you look in .profile you should see something like this:
##
# Your previous /Users/admin/.profile file was backed up as /Users/admin/.profile.macports-saved_2009-08-03_at_14:55:56
##
# MacPorts Installer addition on 2009-08-03_at_14:55:56: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
# MacPorts Installer addition on 2009-08-03_at_14:55:56: adding an appropriate MANPATH variable for use with MacPorts.
export MANPATH=/opt/local/share/man:$MANPATH
# Finished adapting your MANPATH environment variable for use with MacPorts.
If your $PATH hasn't been updated, you should adjust it, since otherwise, you will have trouble using the port tool and the software you install via MacPorts.
I am inclined to think that macports usually keeps all of its stuff inside the /opt/local directory. I am using Leopard, and I have it inside that directory. You may want to look in there, particularly inside /opt/local/bin, to find the ruby binary you are looking for.

Resources