Set up PATH correctly for zsh and RVM - rvm

I just switched to ZSH and are having issues with RVM. I believe it is related to my PATH. One issue that I have is when I start a new tab in iTerm2, the ruby version switches to 1.9.3 even though the default is 2.0.0. Here is my .zshrc file.
export PATH="/Users/okyretina/.rvm/gems/ruby-2.0.0-p353#iou-web/bin:$PATH:$HOME/.rvm/bin:/Users/okyretina/.rvm/gems/ruby-1.9.3-p429#rails-3.2.13/bin:/Users/okyretina/.rvm/gems/ruby-1.9.3-p429#global/bin:/Users/okyretina/.rvm/rubies/ruby-1.9.3-p429/bin:/Users/okyretina/.rvm/bin:/Users/okyretina/bin:/Users/okyretina/xbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/okyretina/phantomjs/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/share/npm/bin"
# load RVM
# insure /usr/local/bin comes before /usr/bin
# PATH="/usr/local/bin:/usr/local/sbin:$PATH"
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# This command should be at the end for it loads the oh-my-zsh.sh script
source $ZSH/oh-my-zsh.sh
my export PATH is very long but I'm not sure which one is no longer needed.

run:
rvm get stable --auto-dotfiles
it will reorganize your shell initialization files to load rvm in proper places, make sure to read all the output - it does print information and warnings that are important.

Probably my answer won't help you to solve your particular problem but I will try to help you in finding a solution.
Your $PATH is pretty long and it's hard to make sure that the files have a correct order. In zsh you can set $PATH like this (example taken from my config):
typeset -U path
path=(
/usr/local/{bin,sbin}
/usr/local/git/bin
/usr/local/opt/coreutils/libexec/gnubin
$path
)
As you can see this method much better in terms of readability and it can help you to make sure that the order in $PATH is correct.
Also in your paths you use both "/Users/okyretina/" and $HOME. I think it makes sense to use $HOME in all cases so your paths will look much shorter and it will be easier to read them.

Related

Why does "rvm use" command require/suggest a login shell?

With a default installation of RVM and from a non-login shell, executing rvm use produces:
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.
Where the reason for this warning is that the following sourcing line is added only in files like ~/.bash_profile during installation:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
And the previous can even be confirmed as expected behavior from https://rvm.io/support/faq#shell_login:
RVM by default adds itself currently to ~/.bash_profile file, and the
recommended way is to enable login shell in gnome-terminal (and
screen).
But, why isn't the RVM installer simply adding the previous line in files like ~/.bashrc so commands like rvm use work both for login and non-login shells?.
Similar questions without a proper/official answer:
Why rvm needs login shell?
https://askubuntu.com/questions/444880/why-do-i-need-to-run-bin-bash-login
The main reason here is that rvm must be defined as a function of your shell and not as a rvm-use script.
If defined as a script, rvm-use would operate in a separate subprocess and only had an access to a copy of your shell environment, not to the original env. Because rvm use needs to actually modify your local PATH environment (to prepend rvm ruby shims for correct version) it needs full access to your shell environment - hence use of function is required.
This means, you need to load this function somewhere - it is (most likely, didn't fully check it) done via /etc/profile, which loads /etc/profile.d/rvm.sh file. This file needs to be either manually sourced or is loaded automatically when terminal opens as a login shell.
Now, why does rvm needs to modify local terminal environment instead of using single global state? It is to allow us to have few terminals open with different ruby versions active at the same time.

rvm doesn't set default ruby with zsh

I'm using zsh in OSX with rvm, but it doesn't load the default ruby at login:
in my .zshrc I have
source $ZSH/oh-my-zsh.sh
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
I've tried to swap those two lines, but still it doesn't work..
(of course in bash it works..)
The issue is that OMZ generated ~/.zshrc with hardcoded PATH, this makes the shell overwrite it every time this file is read.
There is also a bug in ZSH or some mysterious power that makes ZSH read ~/.zshrc after ~/.zprofile - this leads to resetting PATH.
Just comment out the PATH=... line in ~/.zshrc and it should work.
As for the mentioned error - it is supposed to be fixed already, update RVM - rvm get head - and open a new terminal ... if it still appears - open a new issue for RVM.

Installing rvm on Linux Mint KDE

I'm having a hard time getting rvm to install on Mint. I tried the instructions at:
https://rvm.beginrescueend.com/rvm/install/
The first step proceeds without incident. However, when I try to run source ~/.bash_profile, I get an error message stating that no such directory exists. I can restart the terminal, but it still says that "The program 'rvm' is currently not installed...."
A .rvm directory in now present in my home directory and the binary is there. I'm suspecting that this means that I need to add something in my .bashrc (or somewhere else) to tell the OS where to look for executables. But I'm still a little new at Linux and am uncertain where exactly it needs to go or what it should be.
The Answer in the same site:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
it works for me.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
Looks like this needs to be tacked onto the end of the .bashrc file if it isn't present.

Updating files after RVM install

I have installed RVM enroute to updating and running different ruby and rails. After install I received message to update shell's loading files.
1) Place the folowing line at the end of your shell's loading files
(.bashrc or .bash_profile for bash and .zshrc for zsh),
after all PATH/variable settings:
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
You only need to add this line the first time you install rvm.
I typed [[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm"
and hit enter. Does this update my files? Or do I have to open some type of file and cut and paste code?
Since I did not see any notice as stated below from part 2 of the post install, I closed the shell and opened a new one. but the RVM command does not seem to work. Part 2 of the instructions post install was:
2) Ensure that there is no 'return' from inside the ~/.bashrc file,
otherwise rvm may be prevented from working properly.
This means that if you see something like:
'[ -z "$PS1" ] && return'
then you change this line to:
if [[ -n "$PS1" ]] ; then
# ... original content that was below the '&& return' line ...
fi # <= be sure to close the if at the end of the .bashrc.
# This is a good place to source rvm v v v
[[ -s "/Users/eric/.rvm/scripts/rvm" ]] && source "/Users/eric/.rvm/scripts/rvm" # This loads RVM into a shell session.
EOF - This marks the end of the .bashrc file
Be absolutely *sure* to REMOVE the '&& return'.
If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile.
Placing all non-interactive (non login) items in the .bashrc,
including the 'source' line above and any environment settings.
Thanks for the help as I am very new and trying to learn RoR but so far have not been able to get past the setup in many of the tutorials I've attempted. It seems many [
1 2 are out of date with new software or I get error messages before I can even attempt to learn the code. If someone knows of a good beginner tutorial that would be great. Thanks again!
The snippet that the installer gives you need to go in a file called the bashrc. The file lives in your home directory: /Users/eric/.bashrc
You need to edit this file and add the line from rvm and then you should be good to go.
As for getting rolling with rails I'd recommend The Pragmatic Programmers book on rails. You can find their books at pragprog.com
If you're on Ubuntu, my tutorial on setting rvm will get you roll all the way up to rails installation:
http://blog.dcxn.com/2011/06/20/setting-up-rvm-on-ubuntu-11-04/

Autoconf macros for Apache and conf.d install process?

I have a package that is using the autotools to build and install.
Part of the package is a website that can be run on the local machine.
So in the package there is a .conf file that is meant to be either
copied or linked to the /etc/apache2/conf.d directory. What's the
standard way that packages would do this? If possible, I'd like for
the user not to have an extra step to make the website work. I'd like
to have them install the package and then be able to browse to
http://localhost/newpackage to get up and running.
Also, is there a way that autoconf knows about the apache install or a
standard way through then environment some how? If someone could
point me in the right direction that would be great.
Steve
The first thing you should do is to locate the apache extension tool apxs or apxs2 (depends on apache version and/or platform you are building for). After you know where your tool is located you can run queries to get certain apache config params. For example to get system config dir you can run:
apxs2 -q SYSCONFDIR
Here is a snippet of how you can locate apache extension tool: (be careful it may contain syntax errors)
dnl Note: AC_DEFUN goes here plus other stuff
AC_MSG_CHECKING(for apache APXS)
AC_ARG_WITH(apxs,
[AS_HELP_STRING([[--with-apxs[=FILE]]],
[path to the apxs, defaults to "apxs".])],
[
if test "$withval" = "yes"; then
APXS=apxs
else
APXS="$withval"
fi
])
if test -z "$APXS"; then
for i in /usr/sbin /usr/local/apache/bin /usr/bin ; do
if test -f "$i/apxs2"; then
APXS="$i/apxs2"
break
fi
if test -f "$i/apxs"; then
APXS="$i/apxs"
break
fi
done
fi
AC_SUBST(APXS)
The way to use APXS in your automake Makefile.am would look something like this:
## Find apache sys config dir
APACHE2_SYSCONFDIR = `#APXS# -q SYSCONFDIR`
## Misc automake stuff goes here
install: install-am
cp my.conf $(DESTDIR)${APACHE2_SYSCONFDIR}/conf.d/my.conf
I assume you are familiar with automake and autoconf tools.