How to get asdf and rvm to co-exist - ruby-on-rails

Is it possible to have asdf and rvm coexist? If so, how do you set it up? I made a test project to try out asdf but it seems that's affecting another existing project that's managed by rvm. When I run rails I'm getting:
asdf: No version set for command ruby
you might want to add one of the following in your .tool-versions file:
ruby 2.6.1

I've came across the same issue while installing asdf in macOS. I was able resolve it by creating .tool-versions file and adding the ruby version entry. You can do the same by running following command in the terminal.
$ echo 'ruby 2.6.1' >> .tool-versions
more information can be found here in this blog post

This is the hack I currently use. Running use-rvm or use-asdf uncomments the respective line in my ~/.bash_profile, and comments the unwanted line.
# RVM
# source $HOME/.rvm/scripts/rvm
# ASDF
. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash
# Add Visual Studio Code (code)
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
use-rvm () {
sed -i "" 's|^# source $HOME/.rvm/scripts/rvm|source $HOME/.rvm/scripts/rvm|' ~/.bash_profile
sed -i "" 's|^. $HOME/.asdf/asdf.sh|# . $HOME/.asdf/asdf.sh|' ~/.bash_profile
bash --login
}
use-asdf () {
sed -i "" 's|^source $HOME/.rvm/scripts/rvm|# source $HOME/.rvm/scripts/rvm|' ~/.bash_profile
sed -i "" 's|^# . $HOME/.asdf/asdf.sh|. $HOME/.asdf/asdf.sh|' ~/.bash_profile
bash --login
}
And here's the gist

Related

nixos installation issue,'command not found: nix'

I deleted /nix and started a fresh install of nix, however after installing nix install nix (MACBook Pro M1 arm64 BigSur) with sh <(curl -L https://nixos.org/nix/install) I run $ nix but I get the output zsh: command not found: nix , same for nix-shellalso the /nix volume is not created, I also tried the instruction at https://docs.plutus-community.com/docs/setup/MacOS.html still same issue
Open /etc/zshrc and look for the following lines (probably at the end of the file):
# Nix
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# End Nix
Copy these lines and delete them from this file.
Open ~/.zshrc and add the above copied lines to the end of this file
Reboot terminal and nix should work now.

Adaptive Ruby version when opening a terminal

This question is the opposite of this one (also asked here, here and here)
I have two versions of ruby installed
ubuntu:~/environment $ rvm list
ruby-2.6.6 [ x86_64 ]
=* ruby-3.0.2 [ x86_64 ]
and every time I open a terminal window, ruby-3.0.2 (the default) is set. The problem is for a couple of my older projects I have to use ruby-2.6.6, so every time I have to switch with
rvm use 2.6.6
Is there a way to automatically select ruby 2.6.6 when I open the terminal window of the specific projects? I have tried to override the default rvm version with the .ruby-version file (as suggested here) but it does not do the trick.
EDIT File /home/ubuntu/.rvm/scripts/cd contains the following
#!/usr/bin/env bash
# Source a .rvmrc file in a directory after changing to it, if it exists. To
# disable this feature, set rvm_project_rvmrc=0 in /etc/rvmrc or $HOME/.rvmrc
case "${rvm_project_rvmrc:-1}" in
1|cd)
# cloned from git#github.com:mpapis/bash_zsh_support.git
source "$rvm_scripts_path/extras/bash_zsh_support/chpwd/function.sh"
# not using default loading to support older Zsh
[[ -n "${ZSH_VERSION:-}" ]] &&
__rvm_version_compare "$ZSH_VERSION" -gt 4.3.4 ||
{
function cd() { __zsh_like_cd cd "$#" ; }
function popd() { __zsh_like_cd popd "$#" ; }
function pushd() { __zsh_like_cd pushd "$#" ; }
}
__rvm_after_cd()
{
\typeset rvm_hook
rvm_hook="after_cd"
if [[ -n "${rvm_scripts_path:-}" || -n "${rvm_path:-}" ]]
then source "${rvm_scripts_path:-$rvm_path/scripts}/hook"
fi
}
__rvm_cd_functions_set()
{
__rvm_do_with_env_before
if [[ -n "${rvm_current_rvmrc:-""}" && "$OLDPWD" == "$PWD" ]]
then rvm_current_rvmrc=""
fi
__rvm_project_rvmrc >&2 || true
__rvm_after_cd || true
__rvm_do_with_env_after
return 0
}
[[ " ${chpwd_functions[*]} " == *" __rvm_cd_functions_set "* ]] ||
chpwd_functions=( "${chpwd_functions[#]}" __rvm_cd_functions_set )
# This functionality is opt-in by setting rvm_cd_complete_flag=1 in ~/.rvmrc
# Generic bash cd completion seems to work great for most, so this is only
# for those that have some issues with that.
if (( ${rvm_cd_complete_flag:-0} == 1 ))
then
# If $CDPATH is set, bash should tab-complete based on directories in those paths,
# but with the cd function above, the built-in tab-complete ignores $CDPATH. This
# function returns that functionality.
_rvm_cd_complete ()
{
\typeset directory current matches item index sep
sep="${IFS}"
export IFS
IFS=$'\n'
COMPREPLY=()
current="${COMP_WORDS[COMP_CWORD]}"
if [[ -n "$CDPATH" && ${current:0:1} != "/" ]] ; then
index=0
# The change to IFS above means that the \command \tr below should replace ':'
# with a newline rather than a space. A space would be ignored, breaking
# TAB completion based on CDPATH again
for directory in $(printf "%b" "$CDPATH" | \command \tr -s ':' '\n') ; do
for item in $( compgen -d "$directory/$current" ) ; do
COMPREPLY[index++]=${item#$directory/}
done
done
else
COMPREPLY=( $(compgen -d ${current}) )
fi
IFS="${sep}";
}
complete -o bashdefault -o default -o filenames -o dirnames -o nospace -F _rvm_cd_complete cd
fi
;;
2|prompt)
if
[[ -n "${ZSH_VERSION:-}" ]]
then
precmd_functions+=(__rvm_do_with_env_before __rvm_project_rvmrc __rvm_do_with_env_after)
else
PROMPT_COMMAND="${PROMPT_COMMAND%% }"
PROMPT_COMMAND="${PROMPT_COMMAND%%;}"
PROMPT_COMMAND="${PROMPT_COMMAND:-}${PROMPT_COMMAND:+; }__rvm_do_with_env_before; __rvm_project_rvmrc; __rvm_do_with_env_after"
fi
;;
esac
You are probably using RVM as a shell script, and not as a shell function.
You can check like this in a typical shell (bash, zsh, ...) : execute: type rvm
If it displays rvm is /home/ying/.rvm/bin/rvm : you are using as a script (found in $PATH)
If it displays rvm is a function : you are using as a function (much better).
Check out: https://rvm.io/rvm/basics#post-install-configuration
If you are using as a script, and want to use as a function: you need to "source" the rvm function, it is located in <rvm main folder>/scripts/rvm, for instance if installed in $HOME:
source $HOME/.rvm/scripts/rvm
source /usr/local/rvm/scripts/rvm
Typically, at RVM installation time, it add the following line in the equivalent of .profile (depending on shell and if its global or user):
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
RVM changes automatically the version as described here:
https://rvm.io/workflow/projects
For detection of .ruby-version, the following is required:
RVM must be a recent version that supports the feature
RVM must be loaded in the shell (typically by .profile, or equivalent) so that is is executed as a function
the shell must be compatible with this callback feature (bash and zsh are)
Here is what happens:
When you load rvm as a function, it registers callback in the shell
when you cd into the project, RVM callbacks (in shell) detect the file .ruby-version (or others) and automatically do the equivalent of rvm use.
For instance, I use zsh (on osx) which has preexec and precmd callbacks
and it detect the ruby version file and applies when I cd into it or a sub folder.
It works with bash too.
If you are curious or want to see why it does not work for you look at the file <rvm main dir>/scripts/cd
typically the shell variable chpwd_functions is set to __rvm_cd_functions_set
which is the function called after a cd by rvm

Nim(rod) not installing to path properly?

I'm following the isntructions for installing Nim(rod) onto linux. I then followed this site which showed to do this:
$ echo 'export PATH=$PATH:$your_install_dir/bin' >> ~/.profile
$ source ~/.profile
$ nim
Typing nim in the terminal doesn't do anything.
I have a Nim folder in my home directory with all the files but can't use it.
I did echo export PATH=$PATH:$/home/bob/Nim/bin' >> ~/.profile
And the nim command still does nothing. Am I not doing it right?
The command pwd told me /home/bob/Nim when I was in the Nim folder.
I tried running nim with sh in Nim/bin and did ./nim -path:/home/bob/Nim/bin
and it said:
config/nim.cfg(45, 2) Hint: added path: '/home/bob/.babel/pkgs/' [Path]
config/nim.cfg(46, 2) Hint: added path: '/home/bob/.nimble/pkgs/' [Path]
Hint: used config file '/home/bob/Nim/config/nim.cfg' [Conf]
echo 'export PATH=$PATH:$/home/bob/Nim/bin' >> ~/.profile
You appended the location $/home/bob/Nim/bin which doesn't exist. You must remove the $.

etc/bash.bashrc: line 2: GREP_OPTIONS: command not found

When I run a command on my Ubuntu 12 server I get the following warning...
etc/bash.bashrc: line 2: GREP_OPTIONS: command not found
I've probably messed something up by uninstalling various Rails pieces. How can I fix this? This is for the root user. Thanks.
The beginning of my bashrc file has the following...
type rvm >/dev/null 2>/dev/null || echo ${PATH} | GREP_OPTIONS \grep
"" > /dev/null || export PATH="${PATH}:"
It appears that you have uninstalled rvm from your system, as it cannot find $rvm_path_bin. I would recommend commenting out the line from /etc/bash.bashrc.

About Ruby Version Manager Installation

I was trying to install RVM:Ruby Version Manager from:
http://rvm.beginrescueend.com/rvm/install/
I opened up my terminal in my mac os version 10.5.8 and use the command line
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
then I got the message,
"You must now finish the install manually:
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 $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
Please note that this must only occur once - so, you only need to add it the first time you install rvm.
2) Ensure that there is no 'return' from inside the .bashrc file. (otherwise rvm will be prevented from working properly).
This means that if you see '[ -z ] && return' then you must change this line to:
if [[ ! -z ]] ; then
... original content that was below the && return line ...
fi # <= be sure to close the if.
#EOF .bashrc
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 items in the .bashrc, including the 'source' line above
3) Then CLOSE THIS SHELL and open a new one in order to use rvm.
Installation of RVM to /Users/Home/.rvm/ is complete.
kapplej-4:~ Home$ #!/usr/bin/env bash
kapplej-4:~ Home$
kapplej-4:~ Home$ # Install git
kapplej-4:~ Home$ mkdir -p $HOME/.rvm/src && cd $HOME/.rvm/src && version=1.6.5.3
kapplej-4:src Home$ curl -O http://kernel.org/pub/software/scm/git/git-$version.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2645k 100 2645k 0 0 953k 0 0:00:02 0:00:02 --:--:-- 1060k
kapplej-4:src Home$ cd git-$version && ./configure --prefix=/usr/local && make && sudo make install
-bash: cd: git-1.6.5.3: No such file or directory"
I have no idea how to complete installation manually, I am a complete newbie so can someone please give me a step by step instruction on how to do this. For eg, where do I go to add those lines to the shell's loading files?
Thanks,
Not sure why you're installing git through rvm, but my guess is that you didn't extract the tar.gz file before trying to access the directory. Before cd'ing into the git directory you'll need to do
tar -zxf git-$version.tar.gz
To complete the install you need to add the line:
[[ -s $HOME/.rvm/scripts/rvm ]] && source $HOME/.rvm/scripts/rvm
to the end of your .bashrc file (assuming you're using bash which you can determine with echo $SHELL.)
You also need to verify that your bash script doesn't return (the -z return bit in the RVM message. If it does return do what RVM says during the install.)
Once the line is added exit your shell and open a new one. You should then be able to do rvm info to see rvm info and rvm to get more information on RVM.
If Git is already installed, the up-to-date command to install RVM is curl -L get.rvm.io | bash -s stable.

Resources