Installing and running a gem in bash script - bash

I am writing a bash script in mac OSX. now i want to set up librarian-chef,
echo "installing the librarian-chef gem"
gem install librarian-chef
echo "librarian-chef installing cookbooks from the recipies"
librarian-chef install
and then run it. so that the rest of the bash script can complete but i keep getting this line 31: librarian-chef: command not found
so i figured the gem installed fine but the path wasn't refreshed so it couldn't be used? so i tried
echo "librarian-chef installing cookbooks from the recipies"
source ~/.bash_profile
librarian-chef install
so that it would refresh it but that didnt work?
./vagrant_prepare.sh: line 30: ~/.bash_profile: No such file or directory
how can i install it and then use it anyone seen this?
i do have bash profile btw
ls -a
. .bash_history .dropbox .rbenv .viminfo Dumps Pictures temp
.. .bash_profile .gem .redis Desktop Library Public test.sh
.CFUserTextEncoding .bundler .gitconfig .ruby-version Documents Movies VirtualBox VMs
.DS_Store .cache .local .ssh Downloads Music Work
.Trash .config .pow .vagrant.d Dropbox Nexus chronosphere.sh

Add this in your ~/.bash_profile:
eval "$(rbenv init -)"
Reopen terminal and run script again.
#!/bin/bash
echo "installing the librarian-chef gem"
gem install librarian-chef
echo "librarian-chef installing cookbooks from the recipies"
librarian-chef install

Related

Erro install ruby with rbenv ubuntu

I'm trying to set up my Ubuntu environment, and for that I need to install ruby ​​to start working, I have until Friday to get it :/
I'm using rbenv as instructed, I followed the step-by-step instructions, but it didn't work.
I try it:
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
then
rbenv install rbx-5.0
But I get this error:
Downloading rubinius-5.0.tar.bz2...
-> https://dqw8nmjcqpjn7.cloudfront.net/c9e90e3ef2fb80714b09895611152024fecbb3f13955298fa63e57b1785e8ff0
Installing rubinius-5.0...
BUILD FAILED (Ubuntu 21.04 using ruby-build 20210720-1-g37d7143)
Inspect or clean up the working tree at /tmp/ruby-build.20210722014142.33410.qcx0sZ
Results logged to /tmp/ruby-build.20210722014142.33410.log
Last 10 log lines:
Via: 1.1 d5488e7054c0eb6827749a115e047e78.cloudfront.net (CloudFront)
X-Amz-Cf-Pop: GRU1-C1
X-Amz-Cf-Id: HB0MkMd80NIfXeSNOw6h3BURsv4p3ZQfBu5c9nbc4yWKf4xTQ2_xSw==
Age: 1504
/tmp/ruby-build.20210722014142.33410.qcx0sZ/rubinius-5.0 /tmp/ruby-build.20210722014142.33410.qcx0sZ ~/.rbenv/plugins/ruby-build
find: ‘build/rubinius/codedb’: No such file or directory
find: ‘build/codetools/’: No such file or directory
find: ‘build/stdlib/’: No such file or directory
/usr/bin/env: “ruby”: No such file or directory
Seems like everything has broken.
I already do it:
https://github.com/rbenv/rbenv/issues/1067
look at my ~/.bashrc
...
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
I also tried running this command before ruby-build: source ~/.bashrc
How can I solve it?

I can't change the ruby version I want to run with my Mac (M1)

So I tried to do this tutorial https://programminghistorian.org/en/lessons/building-static-sites-with-jekyll-github-pages#on-a-mac-, but got stuck in the ruby section. Here's what happened and what I have tried:
When trying the tutorial I ran into my first "permission" error trying to use this command line
gem install rubygems-update
So I went ahead to the Jekyll website, read the documentation and figured out that I needed to work around that permission error that my guess is that it is generated becase Macs already have a ruby version that they need to run, and also that even if I install a new ruby version I can't change the one my Mac is running.
I tried everything here on the documentation. Even the rbenv path to install ruby and then when trying to see what version I was running with ruby -v, I got the same thing "2.6.3p62".
Then I found this blog post, and again tried to install it that way and again with homebrew. The only thing I modified from there is:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
to this
echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.0.1/bin:$PATH"' >> ~/.zshrc
Because after running echo $SHELL it seems my shell is zsh.
However, when I restarted my console and typed ruby -v the terminal displayed the same old version "2.6.3p62". Also I saw here that I can run which ruby after I installed it and run the echo command to see if it is requiring it from the new defined path but no. It's still inside /usr/bin/ruby
I have run out of options and asking for some help. Thank you.
A possible script for the terminal of an M1 chip MacOS to setup a Ruby (any desired version) environment is:
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git
git config --global color.ui true
git config --global user.name "your name here"
git config --global user.email your_email_here
Then download VS Code in Chrome and go back to your terminal to enter the following commands.
brew install rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc
Next up is where you insert your desired version. This time I suggest 2.7.3
rbenv install 2.7.3
rbenv global 2.7.3
rbenv rehash
gem install bundler pry byebug
gem install pry
gem install pry-doc

ruby, gem, rbenv command not found

I've been setting up some ruby dependencies throughout a day on my Lubuntu (18.04) in VM. I installed ruby 2.4.0 and then installed rbenv and set 2.4.0 as global version to be used (probably reverse order). Then I installed bundler and started installing dependencies for my Sinatra app. Since I needed some native extension I also installed libpq-dev via sudo apt-get install, installed pg gem and ran bundler again. And then I have
Command 'ruby' not found, but can be installed with:
sudo apt install ruby
Same with bundle or gem commands.
I can see that I have rbenv in /home/michalvantuch/.rbenv/bin/rbenv and also /home/michalvantuch/.rbenv/versions/2.4.0/.
My path:
/home/michalvantuch/.rbenv/plugins/ruby-build/bin:/home/michalvantuch/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
My bash history:
bundle install
gem install pg -v '0.21.0' --source 'https://rubygems.org/'
vi /home/michalvantuch/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/pg-0.21.0/mkmf.log
sudo apt-get install libpq-dev
gem install pg -v '0.21.0' --source 'https://rubygems.org/'
bundle install
gem list --local
cd /home/michalvantuch/.rbenv/bin/
ls -lah
C rbenv -> ../libexec/rbenv
cd rbenv -> ../libexec/rbenv
cd rbenv
cd ../libexec/
ls -lah
pwd
cd ..
I'm weary and not sure how to fix this. Did I mess up with the system privileges ?
Complete setup commands for rbenv in linux machines
Initial setup
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
~/.rbenv/bin/rbenv init
check whether eval "$(rbenv init -)" is present in ~/.bashrc. If not present run the following command
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Then,
source ~/.bashrc
mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
source ~/.bashrc
rbenv rehash
Now, rbenv installed. Now install your ruby version ( change the version below to your version). And set that to global version. (Use latest stable version as global as it is a good practice. You can set local versions differently depending on your working project)
rbenv install 2.5.1
rbenv global 2.5.1
Finished.
So, it turns out I figured it out myself.
What I was missing (rbenv doctor helped me) was to have shims in my PATH. Adding
eval "$(rbenv init -)"
did the trick.

Cannot find nginx.conf using passenger-nginx and rbenv

I recently created a Linode server with Ubuntu 12.04 LTS
as the admin user aurelien I installed rbenv (in my case 1.9.3-p194 for my older rails 3.2 app).
Afterwhich I ran gem install passenger and was placed in the directory ~/.rbenv/shims
After that I ran rbenv rehash
and to install nginx:
I couldn't run passenger-install-nginx-module because it asked to use with sudo. When I tried sudo passenger-install-nginx-module it told me command not found.
Then I found this post PhilT's answer
and tried running sudo bash -c "source ~/.bashrc && passenger-install-nginx-module"
/home/aurelien/.rbenv/shims/passenger-install-nginx-module
I went through the entire passenger/nginx installation and pressed "enter" when it asked for the prefix directory.
in my root directory cd ~/home/aurelien and I can't find /opt/nginx.
Did it correctly create these directories?
The only directories/files I have on the root are these:
. .. apps .bash_history .bash_logout .bashrc .cache .gem .gitconfig .profile .rbenv .ssh .viminfo
EDIT: My .bashrc file
export RBENV_ROOT="${HOME}/.rbenv"
if [ -d "${RBENV_ROOT}" ]; then
export PATH="${RBENV_ROOT}/bin:${PATH}"
eval "$(rbenv init -)"
fi
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
The answer posted before by PhilT had the correct code for installing nginx together with passenger:
gem install passenger
rbenv rehash
sudo bash -c "source ~/.bashrc && passenger-install-nginx-module"
The fault in your explanation above is that /opt/nginx is not in user's home directory (~/home/aurelien/opt/nginx), but in the root directory (plainly /opt/nginx.), as nginx is a system-wide install.
(Note: In some other systems nginx also has config files placed in /etc/nginx instead)

rbenv: no such command `init'

I installed rbenv according to the instructions at https://github.com/sstephenson/rbenv#section_2
Restarting my shell at point 4 will result in an error
$ rbenv init -
rbenv: no such command `init'
Trying to run the command directly from its folder doesn't work either.
$ cd .rbenv/bin
$ ./rbenv init -
rbenv: no such command `init'
My $PATH
$ echo $PATH
/home/myusername/.rbenv/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/myusername/bin
Running rbenv install works until rbenv rehash is called
$ rbenv install 1.9.3-p0
Downloading http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz...
Installing yaml-0.1.4...
Installed yaml-0.1.4 to /home/hbrandl/.rbenv/versions/1.9.3-p0
Downloading http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p0.tar.gz...
Installing ruby-1.9.3-p0...
Installed ruby-1.9.3-p0 to /home/hbrandl/.rbenv/versions/1.9.3-p0
rbenv: no such command `rehash'
All other rbenv commands don't seem to work.
Any help or pointers greatly appreciated.
Check if the symlink is correct:
> ls -l ~/.rbenv/bin/rbenv
lrwxr-xr-x 1 kelvin staff 16 Mar 29 11:19 /Users/kelvin/.rbenv/bin/rbenv# -> ../libexec/rbenv
Is your rbenv a symlink to ../libexec/rbenv ? It should be, because it reads that symlink location to know that "libexec" is the location of the other executables.
To fix:
> cd ~/.rbenv/bin
> mv rbenv rbenv.broken
> ln -s ../libexec/rbenv rbenv
It might've broken if you copied the ~/.rbenv from another location, which would probably mess the links up.
A working workaround for my problem was to simply add the libexec folder to my path as well.
My rbenv PATH additions now look as follows:
export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/libexec:$PATH"
This fixes the problem for me.

Resources