rvm and sudo in bash script and rake script - ruby

I need to write some bash scripts and rake scripts to setup my server. However, I'm afraid that it will mess up with sudo in rvm because packages installation in ubuntu require sudo and gem installation doesn't need sudo.
Anyone has some suggestions?

Write two scripts, one for tasks that require sudo, and one for tasks not needing it. Your sudo tasks will have to run first because they're going to do your apt installs. Afterwards run your non-sudo script.
You definitely don't want to run RVM, or gems using sudo if it will be affecting something in rvm's sandbox.
I've set up several hosts lately, and that's the order I do my installs.

Related

Setting up Jenkins with RVM

I am looking for advice on how to correctly setup Ruby/RVM for use with Jenkins. When running Jenkins builds it runs them as Jenkins and I would like to be able to run builds with things like
gem install gemName
Without getting a you do not have permission to write to /Library/Ruby/Gems for example.
Currently this folder is owned by root wheel which explains why Jenkins does not have permission.
What is the best way to set this up? Do I just change the permission on the folder?
I also find myself running builds with
withEnv(['PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH']) {
sh '''npm install
grunt build
gem install gemName
'''
}
Which feels like a bit of a workaround to not setting up my environment correctly ?
One thing I noticed is your not telling Jenkins what rvm gemset you want to use. You also need to set the she-bang.
withEnv(['PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH') {
sh '''#!/bin/bash -l
rvm use 2.3.3#gemset --create
npm install
grunt build
gem install bundler
bundle install
```
}

Command Not Found Jekyll

I'm trying to create and publish a Jekyll blog using this template.
I installed Jekyll initially. Without any luck, I did resort to installing it via sudo. (And have now since uninstalled it!)
Jekyll(1.4.2, 1.0.3) and am running rvm with ruby 2.0.0p195. After installing the gem, I run jekyll serve in the folder but get the error: Zsh Command Not Found. I tried changing my path to no avail. Any advice on how to troubleshoot?
I cannot uninstall/reinstall nokogiri (see other SO articles on this) because of dependencies related to work projects.
If you're using rvm you should not install gems with sudo. Rvm is user-specific (the binaries are all in your home directory), so putting Ruby stuff in system-wide folders with sudo will not work. Just install without sudo and you should be ok.
The rvm docs tries to explain this a little bit here:
http://rvm.io/rubies/rubygems
DO NOT use sudo...
...to work with RVM gems. When you do sudo you are running commands as root, another user in another shell and hence all of the setup that RVM has done for you is ignored while the command runs under sudo (such things as GEM_HOME, etc...). So to reiterate, as soon as you 'sudo' you are running as the root system user which will clear out your environment as well as any files it creates are not able to be modified by your user and will result in strange things happening. (You will start to think that someone has a voodoo doll of your application...)

Mac terminal problems

I recently switched over from windows pc to mac for development and i´m looking for some help regarding the terminal.
When i try to install compass wich is a ruby gem, i´m met with this error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/1.8 directory.
Is there a way for me to execute gem installments etc without doing sudo?
I found out that this "sudo chown -R $USER /usr/local" worked for npm. Now im looking for a way to do the same with ruby and yeoman.
As the commenters have pointed out, it is recommended that you try to use rvm or its cousins, to install ruby into your home directory, this way, you dont need root to install gems by default, and this is more widely recommended.
Alternatively you could try the same chown trick here
try
sudo chown -R <username>:<username> /Library/Ruby/Gems
The second one is usually group name, it can be skipped, or you can let it stay.

how to add rvm to super user

hi i need to execute a ruby program from a init script i need to run the script as
sudo /etc/bin/differ.sh start
but the problem is rvm is not installed on root(super user) . so code in the differ script ruby "filename" wont execute because the gems and rvm is not installed in root.
i need solve how to add rvm and its gems to root (i have not installed by system wide installation).i have even tried the rvmsudo
rvmsudo ruby "filename"
but it's not working in script works good in terminal.
please free to ask any files or outputs i will post along with this question.
This page on integrating RVM with init.d may help: https://rvm.io/integration/init-d

gem issue when using sudo

I have made a script that is already working properly in my development environment with RVM. This script reads *.eml files and parses them.
Now, my problem is this. When I transfer it to the production server, it gives a Permission denied - filename.eml (Errno::EACCES) when reading some files. When I manually read these files using sudo nano filename.eml, it is readable so I thought running my ruby script with sudo is the answer.
But when I tried running it with sudo ruby scriptname.rb, this time it gives me a cannot load such file -- mail (LoadError).
The mail gem is clearly installed and is shown both in gem list --local and sudo gem list --local.
The ruby versions are identical with or without sudo (1.9.3).
The mail gem is also accessible using sudo irb then typing require 'mail'.
Both development and production environments are on a Mac OS with RVM-managed ruby versions.
Any help will be greatly appreciated. Thanks.
maybe the gem is not readable for your server user, such as 'wwwroot', so please make sure the file is 775 mode. e.g.
cd $GEM_HOME
sudo chmod 755 -R .
then everything is readable for other group's users.

Resources