rails wont install on my mac, filepath error? gems error - ruby-on-rails

I cant install rails with the usual commannd it gets ignored on my mac. However it seems to be installed according to the terminal output.

Answer can be found by typing
sudo gem environment
then
gem environment
and comparing the results. (gem env is a short version of the command)
Ruby gems are installed locally in directory under specific ruby version, which is also installed in user specific folder (not sure bout MAC situation, but that's the case on my Ubuntu).
Please see the difference on my machine (I am using rvm - ruby version manager):
with sudo - INSTALLATION DIRECTORY: /var/lib/gems/2.7.0
without sudo - INSTALLATION DIRECTORY: /home/le-hu/.rvm/gems/ruby-2.7.2
Using sudo in this case causes the gem to install under root user, not your regular user profile, this leads into gem missing while trying to invoke the gem script being logged in as not-root user.

Related

Using rvm bundle install doesn't install rails

I'm freshly using rvm for running a legacy project.
I installed rvm fine. Running which ruby gives the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Then running which bundle, also indicates that bundle is using the correct rvm version:
/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin/ruby
Now to get my project running, I run bundle install. It's important to stress on the fact that in my Gemfile I have
gem 'rails', '5.0.7'
Running rails s after those steps, gives:
Rails is not currently installed on this system. To get the latest version, simply type:
Running which rails gives:
/usr/bin/rails
implying that the system version and not the rvm version is being used.
echo $PATH shows:
/Users/Mahmoud/.rvm/gems/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/gems/ruby-2.5.5#global/bin:/Users/Mahmoud/.rvm/rubies/ruby-2.5.5/bin:/Users/Mahmoud/.rvm/bin:/Users/Mahmoud/.pyenv/versions/3.7.2/bin:/usr/local/bin:/Users/Mahmoud/.pyenv/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/openssl#3/bin:/usr/local/opt/libxml2/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/opt/mysql#5.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/MacGPG2/bin:/Library/Apple/usr/bin:/Users/Mahmoud/.ebcli-virtual-env/executables:/usr/local/mysql/bin
My question is, why hasn't rails been installed when I used bundle install? And why is which rails refering to my system and not my rbenv path?
I'll bet your RVM isn't set up correctly and /usr/bin/ appears in your PATH before RVM's bin directory. Run echo $PATH to confirm.
If so, back up your dotfiles for safety and run rvm get head --auto and it should put your PATH right. Logout and log back in or source your dotfiles (source ~/.bash_profile or whatever) and try again.

Rails 6: Cannot install pg on mac m1

I tried installing the gem pg on my mac m1 but am getting this error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
I installed postgresql with homebrew and can connect on a database with the command psql. This means I have postgres install on my machine but the gem pg doesn't work on rails.
The simplest solution is to use sudo and force permissions, however it may not be the best solution.
https://www.moncefbelyamani.com/the-definitive-guide-to-installing-ruby-gems-on-a-mac/
Looks like a good article, you should probably go with https://www.moncefbelyamani.com/the-definitive-guide-to-installing-ruby-gems-on-a-mac/#ruby-manager
If you have installed PostgreSQL with Homebrew, that means you have the write permission to the related directory, as long as you execute the command (be it rails-related or pure Ruby) with the same privilege as you installed PostgreSQL. So, if you have installed PostgreSQL with sudo, then you should run sudo gem install pg or whatever, using sudo. Or, if you have switched your account to an administrator who controls Homebrew software, then you must do the same in running gem install pg (note that this latter case can be complicated in terms of permission if you combine it with a Rails project installed under a user's directory).
Personally, I use rbenv (Github) for the version control software of Ruby (or, a popular alternative rvm should work fine, too), while Homebrew installation is limited to administrators only in my environment. With rbenv, all the Ruby libraries are under each user's control, as everything (but external software like PostgreSQL) is installed under the user's Home directory. This sort of permission-conflict (which really is a pain as I experienced countless times with Rails in the past!) would not happen if you use rbenv (or rvm).

Troubleshooting "Permission denied # rb_sysopen" when attempting to install an earlier version of Rails

Summarizing my problem
Details about my goal:
I want to install an older(stable) version of Rails; specifically 5.2.5.
Describing the expected and actual results:
I expect my Mac running Big Sur v11.3.1 (apple m1) to install Rails successfully.
The actual result is (presumably) a permission/ownership based error:
$ gem install rails -v 5.2.5
ERROR: While executing gem ... (Errno::EACCES)
Permission denied # rb_sysopen - /Users/ayylmao/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/concurrent-ruby-1.1.9/CHANGELOG.md
Obviously I see it's something to do with concurrent-ruby-1.1.9...though I continue to get this error with other gems throughout my efforts to install rails on this new-ish computer.
Describing what I've tried:
Both solutions here - no help
i've read this question - no help
I've read this question, but it's old
I've begun to explore my PATH:
/Users/ayylmao/.rbenv/shims:/Users/ayylmao/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
and I've uninstalled previous installations of Rails (and railties), as well as removed rbenv and re-installed (via the usual for me, Homebrew)
I've run brew doctor, i've updated gems with gem update, i've gotten rid of seemingly superfluous gems with for i in gem list --no-versions; do gem uninstall -aIx $i; done.
Obviously, i'm at my wits end here...
My best guess
looking at my $PATH it seems super "sus"...looks like there's some redundancy...but I'm not certain how to troubleshoot it or if that's the correct place to be looking.
I've dropped most details about my system and environment throughout my question, but here's an agregate:
MacOS BigSur 11.3.1 (perhaps something to do with Apple's SIP?) smh
zsh
homebrew
rbenv
ruby 2.7.2
stating my question without any ambiguity
How do I troubleshoot this error "Permission denied # rb_sysopen" via closer inspection of my $PATH? And is that the most likely culprit?
What steps would I need to take to go completely "nuclear"?
PS - full disclosure...yes I have used sudo in some instance of installing rails...though i've quickly uninstalled those versions shortly after installation. I apologize for the irresponsibility. I was not prepared for the Apple SIP and panicked months ago....Also, ZSH was a change for me as well.
It seems like your ruby installation through rbenv was made via sudo, which will create gem structure with root privileges.
So, when you perform a gem install rails from a regular user, you won't have the privileges to write into gems directory, raising the permission denied error.
You can confirm the permission by running:
ls -la /Users/ayylmao/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/
Try to reinstall your ruby with you own user (without sudo) and the installation of rails or other gems will sould be fine.

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.

sudo gem install rails- this doesn't give me a rails command for bash

I'm on Ubuntu. I type in sudo gem install rails. This works fine, installs railes and 7 other gems fine. Yet $ rails blog is saying this:
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
Type
gem env
It will give you the installable directory where the bins of the gems are being installed. Something like this:
EXECUTABLE DIRECTORY: /usr/bin
Make sure this directory is in your path.
how did you install rubygems, as an admin, or as a user? if you installed it as a user, it may not have the bin directory in your path.
If I were you, (assuming you installed rubygems into your home folder), I would trash that installation dir (not sure where it defaults to, maybe ~/rubygems? or ~/.rubygems?), then run setup.rb from the rubygems tarball as admin (through sudo) I've done this at least a dozen times on ubuntu, and haven't run into the issue you are hitting.
If that isn't the case, could you please link to the blog post you were following?
Make sure your gem executable path is added to your system path so that the system can find the rails executable.
I know this is an old thread but the same error had me stuck. Make sure you add
source ~/.rvm/scripts/rvm to your .bashrc file

Resources