rbenv exec bundle exec instead of just bundle exec - ruby

I'm trying to set up rbenv:
https://github.com/sstephenson/rbenv#section_2
I have this working with one problem: I have to use rbenv exec before everything
So now to do bundle exec I do:
rbenv exec bundle exec
How do I get around this?
Edit
After running rbenv rehash I get:
$ ➔ rbenv rehash
$ ➔ rails s
bash: /usr/local/bin/rails: /usr/local/bin/ruby: bad interpreter: No such file or directory

Silly really:
I forgot to run exec $SHELL so my PATH was not updated. Initially the strings:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
were put into .bash_profile, but should have been in .bashrc. After fixing this I forgot to reopen/run the above command!
Thanks to #Dylan Markov in the comments for pointing me in the right direction :)

Related

How to set path correctly from RBENV shims on Mac M1 with zsh

I'm having trouble setting up the rbenv paths
I follow the instructions as specified here: rbenv installation page
I run the command on a zsh terminal:
rbenv init
The terminal gives me the instruction to run
eval "$(rbenv init - zsh)"
I then close the restart the terminal and check to see if all is configured correctly by running:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
and I get the following failure:
Checking for rbenv shims in PATH: not found
If I try open the fils .zshrc I find only the following path written to it
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
but no shims. Can I add the shims manually? I don't know what it should look like? Or is there any reason the command eval "$(rbenv init - zsh)" is not working properly?
Got it working: I need to run echo 'eval "$(rbenv init -)"' >> ~/.zshrc

.desktop - run RBENV shell - Run app with ruby version

Using RBENV on 16.04 sudo environment.
How to use RBENV shell $rubyversion or similar solution to run a ruby app from a .desktop file for the menu with predefined ruby version?
EDIT:
Heres how i did it with the solution posted by Ḱathryin:
I added interactive shell options to bash, not sure how exactly it works but it helped.
desktop file:
[Desktop Entry]
Name=app
Encoding=UTF-8
Exec=bash -ic "/path/app.sh;${SHELL:-bash}"
Type=Application
The sh exec which runs the app
echo '#!/bin/bash -i
cd /...../appdir
source ~/.bashrc
eval "$(rbenv init -)"
rbenv shell 2.4.1
./app $*
' > app.sh
sudo ln -s /path/app.sh /usr/local/bin/app
running apps with sudo also appears to work!
For the details of setting up a .desktop file, please see: Creating a .desktop file for a new application.
Since rbenv (when installed properly) is a function and not an executable, it won't be as simple as pointing to the right file. One solution would be to create a shell script that sets up the environment:
#!/usr/bin/env bash # Execute as a bash script
eval "$(rbenv init -)" # Initialize rbenv
ruby $* # Run the ruby script specified the .desktop file
Then make sure the script is executable and put it in your .desktop Exec key:
Exec=/path/to/script/ruby_stub.sh script_you_want_to_run.rb ARGS

rbenv: no such command `shell' - Configure RBENV per app/directory on 16.04 sudo environment

Running (x)ubuntu 16.04 with sudo user ...
installed rbenv with local user + sudo plugin
cd ~
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
# sudo plugin
git clone git://github.com/dcarley/rbenv-sudo.git ~/.rbenv/plugins/rbenv-sudo
rbenv install 2.4.1
rbenv global 2.4.1
ruby -v
The shell command is not working with this setup, what am i missing?
Is there a different way than the shell command to set RBENV (rubyversion) for a github project for example?
EDIT1: it appears when RBENV shell is called manually through terminal it works, just not in a #!/bin/bash script
According to your edit, it sounds like the problem stems from not running the script from your interactive shell. Non-interactive shells that aren't invoked with the --login options don't source .bashrc or any other files. You can source .bashrc manually at the start of your shell script:
. ~/.bashrc
You could also just initialize rbenv and not any of your other configurations by adding this line to your shell script:
eval "$(rbenv init -)"

Rbenv not working

I installed ruby 2.0 into ~/.rbenv/versions last and now nothing but that is available
$ rbenv versions
system
*ruby-1.9.3-p392 (set by /apps/test_app/.ruby-version)
ruby-2.0.0-p0
$ ruby -v
ruby 2.0.0.p0
$ env | grep PATH
PATH=/home/cbron/.rbenv/shims:/home/cbron/.rbenv/bin
$cat ~/.bash_profile
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
$rbenv global
ruby-1.9.3-p392
$rbenv local
ruby-1.9.3-p392
$rbenv shell
rbenv: no shell-specific version configured
edit: now set the shell, still nothing.
$rbenv shell
ruby-1.9.3-p392
ruby -v still getting
ruby 2.0.0p0
I already sourced my bash_profile, even restarted the computer.
I had the same issue using zsh and this fixed it:
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
$ echo 'eval "$(rbenv init -)"' >> ~/.zshenv
$ echo 'source $HOME/.zshenv' >> ~/.zshrc
$ exec $SHELL
So basically moving the lines from profile to env!
Extracted from rbenv readme:
rbenv shell
Sets a shell-specific Ruby version by setting the RBENV_VERSION
environment variable in your shell. This version overrides
application-specific versions and the global version.
$ rbenv shell jruby-1.7.1
When run without a version number, rbenv shell reports the current
value of RBENV_VERSION. You can also unset the shell version:
$ rbenv shell --unset
Note that you'll need rbenv's shell integration enabled (step 3 of the
installation instructions) in order to use this command. If you prefer
not to use shell integration, you may simply set the RBENV_VERSION
variable yourself:
$ export RBENV_VERSION=jruby-1.7.1
So in order to use it you need to specify the ruby version as rbenv shell argument (f.e. rbenv shell 2.0.0.p0, or set RBENV_VERSION (f.e. export RBENV_VERSION=2.0.0.p0)
TL;DR: just reinstall rbenv, unless you are as stubborn as me...
I had messed up permissions in the .rbenv folder, so the shims weren't loading because they didn't have execute permissions
chmod u+x ~/.rbenv/shims/*
Disclaimer
I had deeper permissions problems, rbenv wasn't even working, so I did other chmod u+x ... previously
chmod u+x ~/.rbenv/libexec/*
chmod u+x ~/.rbenv/**/bin/*
Probably easier and safer to just reinstall rbenv. But this was fun!

Initialize rbenv and run ruby script from shell script

Initialize rbenv and run ruby script from shell script
I want svnserve to run pre-commit hook, written on ruby. As the svnserve is run as root user, it knows nothing about user rbenv installation.
I set a soft link /usr/bin/ruby -> /home/admin/.rbenv/shims/ruby .
As result, when i try
#!/usr/bin/ruby
puts "Pre-commit hook!"
It shows error:
Transmitting file data .svn: Commit failed (details follow):
svn: Commit blocked by pre-commit hook (exit code 255) with no output.
When i run manually on Server:
admin $ sudo ./pre-commit
/usr/bin/ruby: line 4: exec: rbenv: not found
So, i suppose, that rbenv initialization is needed, but how?
In hooks path:
pre-commit:
#!/bin/bash
export HOME=/home/user
if [ -d $HOME/.rbenv ]; then
export PATH="$HOME/.rbenv/shims:$PATH"
eval "$(rbenv init -)"
fi
$0.rb $*
pre-commit.rb:
#!/usr/bin/env ruby
ARGV.each_with_index { |arg, index| puts "Index #{index}: Argument #{arg}" }
you should initialize rbenv before using it.
/path/to/user/home/.rbenv/bin/rbenv init
then set ruby version globally:
rbenv global DESIRED-RUBY-VERSION
or localy:
rbenv local DESIRED-RUBY-VERSION
or per shell:
rbenv shell DESIRED-RUBY-VERSION
though not sure shell setting will work without a tty.
so you could create a shell script, pre-commit.sh and register it as a svn hook.
inside it initialize rbenv and call your pre-commit.rb file

Resources