Permission issues since upgrading to Ruby 2 and Rails 4 on OSX - ruby-on-rails

I recently upgraded to Ruby 2 and Rails 4
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
$ rails -v
Rails 4.0.0
Now, when I create a new rails app, when the bundle install part happens, I get asked for my system password, which never used to happen before. It also takes forever. Reference screenshot: http://i.imgur.com/6kh4g63.png
Secondly, whenever a gem shows up in my Gemfile which I don't already have, it requires installation. In this case, I flat out get a permission denied error. Reference screenshot: http://i.imgur.com/rcIq5Vq.png
Also, when I want to run "rake db:migrate", I have to run it with sudo now, whereas previously this wasn't the case. If I do sudo bundle install, then even my Gem installation problem gets fixed.
However, this is not how my workflow used to be, and I want to figure out why this is suddenly the case. Even my rails server which I previously could start by simply typing "rails s" now requires me to type "sudo rails s".
Does anyone know what is causing this and how I can fix it?
Thank you.

Okay, so I think I've solved it. Not sure if this is good practice or not, but it worked, so I thought I'd answer it:
First, I found out where my rails is located, by typing: "which rails"
It gave me: /usr/local/rvm/gems/ruby-2.0.0-p247/bin/rails
So I went to that folder: cd /usr/local/rvm/gems/ruby-2.0.0-p247/bin
I saw that everything was owned by root. So I changed that to my username:
sudo chown -R Myname *
I did the same for ruby: "which ruby"
cd /usr/local/rvm/rubies/ruby-2.0.0-p247/bin
sudo chown -R Myname *
I thought this would work, but when a new gem would install, the folder it would try to copy in would not have write permissions for my username. This folder was: /usr/local/rvm/gems/ruby-2.0.0-p247/build_info/
So I did: cd /usr/local/rvm/gems/ruby-2.0.0-p247
And then owned the folder: sudo chown -R Myname build_info
And voila, everything is working now.
Please correct me if this is bad practice or unsafe.
Thank you.

Related

Turning off Rails in Mac Terminal

I'm learning to use Bootstrap and spent the last few hours wrestling with Terminal as I tried to install the software that accompanies it - Ruby, Rails, SASS and two or three more. It was a failure, though I did get most of the programs installed.
Now it appears that Rails has hijacked my Terminal. I tried installing another toy I wanted to try out, Symfony. When I type in the install command
$ curl -LsS http://symfony.com/installer > symfony.phar
$ sudo mv symfony.phar /usr/local/bin/symfony
$ chmod a+x /usr/local/bin/symfony
I get this message:
-bash: $: command not found
Davids-MacBook-Pro:Rail myname$
I get the same message if I type in $ php --version
Anyway, the word "Rail" leads me to suspect that Terminal is in Rails mode. Can anyone tell me how to turn it off? I wasn't allowed to ask about it on the Apple forum; they seem to have a problem with questions related to this topic. ;)
Thanks.
P.S. I'm using OSX Yosemite.
The commands to install symfony, make sure you enter them one at a time and don't include the $ which is causing the error.
You can configure what appears currently as
Davids-MacBook-Pro:Rail myname$
by going typing cd to go to your home directory and than nano .bash_profile
By the way Bootstrap is just a css, html, and a bit of javascript framework/library that you can use with a bunch of different languages doesn't have to be Ruby on Rails. Also ruby is installed on yosemite by default but you might need to update it and Rails automatically includes SASS (Both Rails and SASS are gems).
The :Rail in Davids-MacBook-Pro:Rail myname$ indicates that you're currently in a folder named Rail. There is no "Rails mode," and Rails will not "hijack" your terminal.
Type the pwd command to reveal which folder you're in (which I'm guessing is a folder named Rail).
If you cd into another folder, your command prompt will update to reflect that:
Davids-MacBook-Pro:Rail myname$ cd ~/Desktop
Davids-MacBook-Pro:Desktop myname$

Rails - Closed terminal and rebooted machine - now bash tells me rails isn't installed

Running OSX Mavericks, ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0], rvm 1.25.23 (master), and rails-4.1.0 (allegedly)
I'm working through the railsapps.org book on learning rails and made it about 1/2 way through yesterday. When I stopped for the day, I closed out iTerm2 and shut off the Macbook Pro. Today, I powered up, opened iTerm, navigated to my working directory (~/rubyonrails/learn-ruby) and entered rails -v.
I see this:
`Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.`
So I run sudo gem install rails and it shows that it has installed rails-4.1.0. Now rails -v still gives me the same error message above.
I tried also running rvm use ruby-2.1.1#learn-rails first and I still get the error message.
So I'm a little stuck and I can't figure out what to do to get rails working. Also, how do I go about setting up the bash environment such that I don't have to go through this each time? It would be nice to nav to my working directory and just start work without having to do a bunch of re-installation and reconfiguration each time.
Regards,
Jeff
please type in your shell:
$ bash --login
and then repeat your commands.
rails -v
Also try to call it with the full path:
like:
/your/path/to/rails -v
I think that the shell just doesn't know where rvm/rails etc is located.
You can solve this by entering:
$ source ~/.rvm/scripts/rvm
When you switch to the ruby-2.1.1#learn-rails ruby/gemset combo, and do gem list, what do you see?
The way people usually use rvm is to have every project folder specify the ruby & gemset it uses (they don't all have to be different). This is done with files called .ruby-version and .ruby-gemset. These should contain, in your case, ruby-2.1.1 and learn-rails respectively.
Set these if you haven't already, then leave the folder and enter it again. Then do bundle install to install the gems for the project into the rvm/gemset combo.
Your problem is that you ran
sudo gem install rails
The error message telling you to do this comes from your system Ruby, which doesn't know that you want to use RVM.
RVM installs gems into your user-space directory. By using sudo, you're bypassing this and installing it into (effectively) the superuser space, i.e. globally.
If you instead just run
gem install rails
then you'll be using RVM's copy of the gem utility rather than the globally installed version.

"bad interpreter: Permission denied " error while trying to execute rails commands

I am using ubunutu natty narwhal.I had installed ruby,rails,rvm etc.. sometime back and everything was running peacefully.Recently i tried to execute "rails -v" on the command line i get this frustrating error.
roger#roger-Inspiron-1545:~$ rails -v
bash: /home/roger/.rvm/gems/ruby-1.9.2-p180/bin/rails: /home/roger/.rvm/rubies/ruby- 1.9.2-p180/bin/ruby:
bad interpreter: Permission denied
I also get this error for other rails commands i execute
Can someone let me know what the problem is and how i can fix this.
Update:Whereis ruby gives me the this
roger#roger-Inspiron-1545:~$ whereis ruby
ruby: /usr/bin/ruby /usr/bin/ruby1.8 /usr/lib/ruby /usr/share/man/man1/ruby.1.gz
Thanks
run:
ls -l /home/roger/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
The first few characters of the entry should be "-rwx" and you should see your own username as the owner. If you don't see at least the "r" and the "x", run
chmod 755 /home/roger/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
to give the owner read/write/exec and everyone else read/execute.
If you aren't the owner, you'll need to do "sudo chown" to fix that.
I suspect that there's a bigger underlying problem though. If you have other ruby versions installed, switch to them in rvm, type "which ruby" and run "ls -l" on them as well.
Did you do a restore from backup recently? Maybe the permissions weren't correctly restored. Or did you run some kind of script that might've been too aggressive in changing owner or permissions? Or maybe you accidentally did a chmod or chown?

Ruby on Rails and Ubuntu: typing just "script/generate ..." instead of "ruby script/generate"

I'm using Ubuntu 10.04. In the terminal, when I go to my app and type (without using the "ruby" in front):
script/generate controller recipes
I get a "Permission denied" error. When I use this however:
ruby script/generate controller recipes
everything works as expected. Is there something I have to do to Ubuntu to make the prepended "ruby" unnecessary when I'm trying to generate controllers (i.e. just using "script/generate controller recipes" should just work)?
chmod 755 script/generate
Type
ls -la
in the script folder to see the permissions of the generated script.
It probably doesn't have the execute permission (x).
I recommend reinstalling rails.
wow, that's strange,
congrats on switching to linux.
how did you install Ruby? Did you do it from the synaptic package manager? Did you run sudo aptitude install ruby or something like that?
whatever you have done, you might be best installing RubyVersionManager (RVM) - it's really easy - there's a railscast on how it works here: http://railscasts.com/episodes/200-rails-3-beta-and-rvm
I've never had or heard of the problem you've got there

How to completely wipe rubygems along with rails etc

Ok, so I decided I'd be cool and try to use Rails3 that's in beta. Then, things were getting hard to manage so I got rvm. I installed ruby 1.9.2-head in rvm and things were working, and then a computer restart later rails wouldn't start up. So I figured I'd just try running the system ruby and start rails in it. same error. Then, I uninstalled rails3 and got rails: no such file or directory type errors..
So now I'm royally screwed because rails2 is still installed but will not uninstall because of invisible dependencies, along with a lot of other random gems. How do I completely clear out all ruby gems and such so I can start anew?
I've recently had to so just this. I had built up alot of cruft with my system installed ruby and gems and wanted to clean all that out and move everything over to run under rvm for various projects.
1. Clean up old and busted
First thing I did, before messing with rvm (or run rvm system to get back to the system ruby), was to remove all my gems:
gem list | cut -d" " -f1 | xargs gem uninstall -aIx
WARNING: this will uninstall all ruby gems. If you installed as root you may want to switch to root and run this.
2. Install new hotness
Now you can run gem list to see what is left.
Time to install rvm, I recomend blowing away your current install and reinstall fresh:
rm -rf $HOME/.rvm
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Now the real trick is to use gemsets to install rails 3, and this is easy if you follow Waynee Seguin's gist:
rvm update --head
rvm install 1.8.7
rvm --create use 1.8.7#rails3
curl -L http://rvm.beginrescueend.com/gemsets/rails3b3.gems -o rails3b3.gems
rvm gemset import rails3b3.gems
One difference is I use 1.8.7 since I have had issues with 1.9.2-head and RSpec, but 1.8.7 has been smooth.
You say that you already got Rails 2 and afterwards installed rvm. Try if you can remove Ruby and Rails using the package manager of your system (yum, apt, ...)
The error you got is most likely the result a link in some general place which still exists, but is pointing to the real installation directory which no longer exists.
For example: /usr/bin/ruby exists and is pointing to /usr/local/lib/ruby/1.9.2/bin/ruby which no longer exists.
Afterwards manually clean out any Ruby and Rails related paths in /usr and its subdirectories.

Resources