Why rvmsudo is needed to install passenger - ruby-on-rails

I have browsed around but unable to find why rvmsudo is needed for passenger installation.
I am installing passenger with nginx in my server and I'm using RVM. According to the passenger user manual I need to use rvmsudo to install passenger if I have rvm installed.
Whats the difference between using rvmsudo and without using rvmsudo. Is using rvmsudo to system wide install needed despite having rvm installed locally only ? (just use gem install passenger)
Thank You !

sudo grants a command root permissions to the current user to carry a certain activity (given the user is allowed to use sudo). That said, on installing passenger you need root permission to install files at required locations.
One simple thing to do that comes to mind instantly is:
sudo rvm passenger-install-nginx-module
This won't work! Here's the explanation:
However, this won't work at all. sudo will start a new subshell.
That new subshell's environment will be completely different, and
won't contain RVM, nor will it have access to your user's RVM without
trying to hack in RVM's environment variables yourself.
Therefore you are required to use the solution provided by RVM i.e. rvmsudo. It will pass on any environment variables that RVM set up to get you to the correct Ruby along with sudo privileges, which is exactly what you need to install passenger in this example.

Related

RVM says it is using 2.7.3, but ubuntu says i am on 2.7.0

Using Ubuntu, I ran the command
rvm use 2.7.3
I then ran
sudo rake db:create
and was greeted by the error
Your Ruby version is 2.7.0, but your Gemfile specified 2.7.3
Am I doing something wrong here? I have been battling with this for hours and have no idea how to proceed
The $PATH variable when using sudo is not the same as the $PATH for your non-sudo user. Because RVM works by modifying $PATH, the RVM modifications are lost when you invoke sudo. That's why RVM stops working with sudo.
If you really need to run something as root using RVM, then you can try it with rvmsudo instead.
You can read more here:
rvmsudo vs sudo?
Also check the manual for rvmsudo:
https://rvm.io/integration/sudo
However in your case it's better to adjust access to the database, so that root privileges are not needed for Rails to connect to the DB.

Rvm ruby Permission denied

I have installed rvm for multiuser,
when I am doing bundle install, it is giving me error,
linux:/var/rails_apps$ bundle install
ERROR: RVM Ruby not used, run `rvm use ruby` first.
linux:/var/rails_apps$ rvm use ruby
mkdir: cannot create directory `/usr/local/rvm/log/ruby-2.0.0-p247': Permission denied
I already did,
sudo chmod 777 /var/rails_apps/
Please suggest..
You have a multiuser installation of rvm - this is not recommended because of the troubles you can get with it (like yours).
Since you are already there this should fix it:
rvmsudo rvm get stable --auto-dotfiles
rvm fix-permissions system
Also make sure you are in rvm group - if not add yourself:
rvm group add rvm $USER
and log in to a new shell (log out and log back in).
In most of the cases rvm fix-permissions will resolve the problem for single user access but it fails in some cases while making other rvm commands thereafter. So do it with rvmsudo after the fix-permissions command consecutively as
rvm fix-permissions
rvmsudo rvm use ruby
For those who may have issues after running the commands shared on every thread out there, try opening ubuntu or the Linux environment you are working with as an administrator.
1 - Search for your app (in my case Ubuntu) using the search bar on the bottom-left of your computer's screen.
2 - if you don't see the option "open as administrator" on the right side, then right-click over the app's icon and you should see it then.
3 - Allow the app to make changes on your computer when prompted and then try the installation commands again.
4 - If that didn't work then try the commands shared in this or other posts, but always as administrator.

Where to install Nginx when using rvm

Where do I want to install Nginx when I am using RVM. It defaults to the system version 1.8.7. I need it to use 1.9.3
Where do you want to install Nginx to?
Please specify a prefix directory [/opt/nginx]:
First of all, specify your ruby version.
rvm install 1.9.3 (if you don't already have it)
rvm use 1.9.3 (--default)
Then you need:
gem install passenger
cd /your gems dir (such as ~/.rvm/gems/ruby-1.9.3-p0/gems)/passenger/bin
./passenger-install-nginx-module
What about destination directory? All to your decision:
if it's developer's/learning machine - recommend to install in ~/nginx
if it's something like 'production' - create user for web application, cut him rights, install rvm and all rails enviroments for him, nginx install to common directory (/opt/nginx) for access to nginx from several accounts simultaneously.
General rule: RVM & Rails (web app) is for one user => nginx may be for one user. In a different way => global

How to manage ruby gems in linux?

As I have started using Linux (Ubuntu) to broaden my knowledge, but the flow for ruby (rails) development does not feel so smooth as on Mac OSX.
Do you use rvm to manage ruby gems in Linux?
One particular issue I face is that I could install rails with only sudo command. But this forces me to use sudo for all the time under my rails project.
P.S.
Might be I am missing some point with the way you do things in Linux so it is not related to ruby (or rails) at all.
It is preferred to use rvm. we can install ruby and rails without rvm as well, but we can have only one version at a time. You can find the instructions to install rvm from following link - rvm installation.
If you are the only person working on ruby rails, install in single user mode(doesn't need to go with sudo)
Installing ruby and rails only using superuser privileges means you're installing it from distribution packages. That's not recommended, and you get unneeded overload writting sudo before any rails command.
Install rvm or rbenv in your home directory and things should be smooth.

Passenger no such file to load --bundler

I'm trying to deploy a rails app under apache (on Ubuntu 11.04) for the first time and I'm running into some issues. Basically, when I hit the site, I get an error:
no such file to load --bundler
I'm running rails 3.0 under apache and using passenger. Currently, the app lives under a subdirectory of a user directory. I've installed rvm and have pointed apache at the directory. I did a bundle install to install all the gems.
However, I think I may have screwed up by putting the site in a user directory. Should I move it somewhere under /var/www? I'm thinking that it is entirely reasonable that apache is not getting the same gemset that I have installed for the user. What do I need to do to get the user that apache is running under to have the same rvm capabilities?
I'm a bit clueless on what information you guys need to help me, so please clue me in.
Did you install the necessary gems for Rails? Install bundler by executing gem install bundler. Then go into your Rails app and type bundle install.
Also, after bundler is installed, type which bundle to see if it's in your $PATH.

Resources