Where do you run "gem install bundler" to make your own gem? - ruby-on-rails

I'm trying to make my own gem, but I don't know where to run "gem install bundler" in my terminal. And when I ran it in my directory where I have all the other rails projects in it, it first said Permission denied # rb_sysopen /Users/km/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/.codeclimate.yml
so I decided to chmod this .codeclimate.yml file to 755, but it still gave me the same error so I did chmod 775, and now it gave me this error:
Operation not permitted # chmod_internal - /Users/km/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/.codeclimate.yml
I have no idea what I'm doing. I am new to unix commands and rails and still have no idea what this file even is or what permission I need to change. Can someone help, please?

Generally, to achieve some sorts of structure I created different workspaces for my projects. So I have a folder for gems, templates, projects.
In your case, I don't think you should be trying to modify the permissions on your workspaces, rather create a work directory where you have permissions to.
Since you mentioned that you had a project you had your other rails projects in, I'd assume you already have bundler installed.
To create your gem IMHO, you should:
Create a directory for your gems
Run bundle gem name-of-your-gem-here
If you navigate to this project folder, you should see the boilerplate for your gem has been generated.
Hope I was able to help.

Related

Trying to create a rails app but keeps failing to setup

I'm trying to create my first rails app. I'm on a Macbook Pro, so macOS.
I've been following this guide setting up rbenv, rails etc.
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-macos
Then I'm following a crash course on YouTube. In the terminal I try to create a new rails app
rails new foodlog
It starts to set up in the folder I made for it, but the following happens during setup
Bundler::PermissionError: There was an error whle trying to create
'/Users/myusername/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0/racc-1.6.0'.
It is likely that you need to grand executable permissions for all parent directories and write permissions for
/Users/myusername/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0'
This error continues repeating the same thing with things such as "strscan".
Then after it says
In gemfile:
rails was resolved to 7.0.3.1, which depends on
actionmailbox was resolved to 7.0.3.1, which depends on
net-imp was resolved to 0.2.3, which depends on
stscan
run bundle binstubs bundler
Could not find gem 'sprockets-rails' in locally installed gems.
rails importmap:install
Could not find gem 'sprockets-rails' in locally installed gems.
Run 'bundle install' to install missing gems.
rails turbo:install stimulus:install
Could not find gem 'sprockets-rails' in locally installed gems.
Run 'bundle install' to install missing gems
I've tried looking online, coming across similar but not exact issues. For example, one solution suggested doing bundle install in this directory, versus where the guide says do it in the home directory. So I do that and get
Bundle complete! 0 gemfile dependencies, 1 gem now installed.
Still doesn't do anything. I think the main culprit is the permissions error it mentions above? This is my first time trying to really do any development on the macOS and I'm sure there's just a misunderstanding somewhere regarding permissions, so if anyone can help that would be appreciated!
It is likely that you need to grand executable permissions for all parent directories and write permissions for
/Users/myusername/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/extensions/arm64-darwin-21/2.7.0'
Your question does not mention, so I think you might have missed this suggestion. Make sure all directories have the executable permission

Gem corruption: Zip end of central directory signature not found

i'm new with Ruby and i never used gem files. I had to install offline some gem files. Unfortunately i followed another procedure, instead of following the documentation so i wrote a script to go through the folder "gem" of my installation directory and run first "build" and then "install --force --local ". The "clean" way would have been running just this last command but in the "cache" folder of the installation directory.
I suspect this corrupted my gems. In fact, when running my software (based on this gems) i get this error:
/var/lib/gems/2.6.0/gems/rubyzip-1.3.0/lib/zip/central_directory.rb:143:in `get_e_o_c_d': Zip end of central directory signature not found (Zip::Error)
The only idea i've is to clean up and re-install the gems, but i know that bundle clean --force can not be used that easily, since it can destroy also other gems not related with this last installation.
Do you have any suggestions?
Thank you

Permissions error with gem install

I had a very weird problem yesterday, where in the middle of trying to figure out some heroku problems, my whole Rails environment just disappeared. Bundle, RVM, rails, etc were no longer recognized. So I just ignored the possible cause and reinstalled everything. Mostly worked, but now I'm running into permissions problems. If I bundle install, it needs me to input my computer password for permission.
And I just ran into the following problem trying to "gem install heroku" in a new directory I wanted to deploy.
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.
Any idea how I get those permissions back so things run smoothly again?
Thanks!
Use chmod on the directory something like this:
sudo chmod -R g+w /Library/Ruby/Gems/1.8
That might work.

RVM why don't gems install to locally to project folder?

So here's my problem:
I have a project and I am trying to install Gems locally to that project. For example if I install devise from the Gemfile and then run a bundle install it won't put any of the controllers in the controllers directory of the project. Instead I have to hunt through the RVM directories to get that particular gem's controllers, copy them to my project and then start writing my project from there.
Any suggestions?
I think the comment above answered your question - when you add a gem like Devise to your app, it doesn't generally drop code directly into your application. Sometimes it provides a generator which will install some parts of it, but mostly it alters config files so that the code in the gem gets pulled into your app when it starts.
You can ask bundler to install gems in the "vendor" subdirectory of your app, instead of in the main RVM/Ruby location, with the --path option. But you usually only want to do that for production deployment, not development.

Files added to my Ruby Project when using RBENV

After installing RBEnv and rebuilding my ROR project, I now seem to have added many, many files to my project. They are in /vendor/local, and appear to duplicate what you would normally find in /Library/Ruby/Gems.
My project will not run without these files present (I get the message Could not find rake-0.9.2.2 in any of the sources.
I had difficulties with my RBEnv installation. I have what I suspect are other issues (like I have to bundle exec rails instead of just running rails). I suspect that I have done something wrong and should not have these files in my project. What I'd like to know is:
1) Should these files be there?
2) How best to fix this (if this is not how it is supposed to work)?
3) If the best approach is to start over and reinstall rbenv, how do I clear it all out?
It is true that using RBENV will end up putting copies of your gems in the project's /vendor/local folder. This is to remove any dependencies on your base gem set. These files need not be part of your source repository, as long as your 'gemfile' and your '.rbenv-version' file are included in the repository.
Another price you pay for using rbenv is that you must bundle exec rails <command> and bundle exec rake <command> from here on in.

Resources