How to stop rails new from creating vendor/cache folder? - ruby-on-rails

Earlier I ran these commands:
bundle install --path vendor/cache
and
bundle config set path 'vendor/cache'
And now,
Whenever I am doing
rails new app_name,
a folder vendor/cache (with 5K+ files) gets created inside the app_name directory.
How can I undo the above first two commands so that everything comes back to normal?
I don't want vendor/cache to be created every time I do rails new.

Running this should undo the damage.
bundle config unset path
See more in the documentation

Related

Best way to reset a ruby on rails project

We have a ruby rails project which we normally get from our enterprise github repository. Recently, I've added dependencies that for some reason breaks my other projects that are not related to the one I was working on. My questions are
Does "bundle install" saves the dependencies globally? or can it behave like the npm to install on current project?
Can I undo "bundle install" by using "bundle clean --force"? after doing this and running "bundle install" again it doesn't to make any changes (not showing "Installing" instead it's say "Using"
I tried removing the the version of ruby since I found out that runing "bundle install" creates a directory /usr/share/rvm/gems/ruby-2.7.2#ruby_test_setup_engine/. But my issue was still there.
I also tried deleting the project folder and cloning it again but since
/usr/share/rvm/gems/ruby-2.7.2#ruby_test_setup_engine/ was created it didn't do anything at all.
Not sure what kind of issues you are facing. but based on your question here is the details:
Does "bundle install" saves the dependencies globally?
No it's not saves globally, it's saved specific to project and more specific to gemset you are using.
Can I undo "bundle install" by using "bundle clean --force"?
No, this command just cleans up unused gems in your bundler directory.
But you can undo your bundle via rvm gemset empty.
Removing gem directory won't help as it will create as soon as you run bundle install command.
Another way to reset you gemset is remove your Gemfile.lock and copy from original source and re run bundle install.
Hope this info will helps.

How to avoid entering password for new Rails app?

After I run rails new myapp, it downloads gems and then at run bundle install, I always get prompted to enter in my system password.
Is there a way to set the password so I don't have to keep entering it in?
Background info
Why do you have to enter the password in the first place? Because by default bundler will install gems in a system wide location, such as /usr/local/lib/ruby/gems/2.2.0/gems/.... These gems can be used by every user on your pc.
Because it is a shared location, it is usually only writeable by root and therefore you have to enter your password to gain root privileges.
Where are your gems stored? Find out by using bundle show <gem> for a specific gem, for example rake, which in my case says:
bundle show rake
/usr/local/lib/ruby/gems/2.2.0/gems/rake-10.4.2
Solution
a) Change owner of directory
Either make this directory writeable for you. But this is no good practise, because system folders should not be writeable for a normal user. In case you are the only user it still might be OK - then you can simply change the owner of this directory to be you:
sudo chown -R `whoami` /usr/local/lib/ruby/gems/
Now you are the owner and can change files inside without the need of any password.
b) Install gems locally inside project dir
Or you can install all gems locally inside your project dir using the --path option of bundler. It is a convention that those gems are normally installed in vendor/bundle, so you use this command (you can use any path you want):
bundle install --path vendor/bundle
(When you do bundle update next time, you can omit the --path option, because it is saved in the .bundle folder of your project.)
You should add the vendor/bundle folder to your .gitignore (or whatever vcs you are using) to not have it checked in.
Since you write inside a directory you own, you do not have to enter a password. The downside of this is that gems will be duplicated in every project folder if you have multiple projects using the same gems. For a multi user system this is the correct way. But if you are the only one using the machine, variant a) definitely helps to save space and install time.
I'm using variant a) on my own development machine and variant b) on the deployment machine.
It seems like a permissions issue. Try chmod a+w /path/to/bundler

Bundler create an update folder when I do bundle install

I haven't upgrade my gems for a long time, just today, I decided to run a upgrade. I probably made a mistake at first running bundle install update, which didn't do anything. Then I ran bundle update, and it created a whole new folder called update in my rails directory containing all the gems, and it seems like my rails project is no longer linked to my rvm gem directory because if I remove the update folder it fuzzes about not being able to find gems. I'm just wondering if this is the new behavior to rails or it's because I did something wrong. Thanks!
Edit:
The output of bundle config is:
Settings are listed in order of priority. The top value will be used.
path
Set for your local app (/Users/X/dev/tasker/.bundle/config): "update"
disable_shared_gems
Set for your local app (/Users/X/dev/tasker/.bundle/config): "1"
This seems to be the problem. So how should I revert it to its state before by linking to the rvm gem directory? And is the problem caused by my 'bundle install update' command? Thanks!
Edit again:
Thanks for the help guys. After finding out the root issue of my problem, I found this solution: bundle install --system at How can I fix an accidental 'sudo bundle install dir_name'?. Now the problem is solved. Thanks!
I made same mistake.
Check command line options for bundle. bundle install accepts directory. and if you type bundle install update, it install the bundle onto the directory.
If you did, bundler create .bundle/config file and store the given path in the file.
I think, just removing .bundle directory and run "bundle" will bundle the needed files,
will use the gems in RVM (if RVM configured correctly).

Rails bundler: how to undo bundle package?

How do I undo bundle package?
I deleted everything in vendor/cache but it is reinstalled there when I run bundle install.
As per this answer: https://stackoverflow.com/a/9471980/219883
You must delete the hidden .bundle directory, then re-run bundle install - otherwise it will continue to add the vendor/cache directory back every time.
But if you just to remove a particular gem, then remove/comment the name of the gem from your project/Gemfile and then run bundle.
To prevent gem files from being added to the vendor/cache directory delete the vendor/cache directory from your project root.
The next time you will run bundle install gems won't create a vendor/cache folder.
Later on in your project if you need the vendor/cache folder all you'll have to do is to create the folder vendor/cache again.
.bundle/config is telling bundler to put things in vendor/cache. Either remove the following two lines from .bundle/config or remove .bundle/config itself.
---
BUNDLE_PATH: vendor/cache
BUNDLE_DISABLE_SHARED_GEMS: '1'
Then run the following command to remove vendor/cache:
rm -rf vendor/cache
The next time you run bundle install you will not have this problem.
$ rm vendor/cache -r
$ bundle install
This might help as well. For more details see the documentation on bundle install
bundle install --system
Pretty late to answer, but this was happening with me too. You probably have hidden directory .bundle in you application root directory. Remove that directory too and then run bundle command.
You can check your config with (under your project directory):
bundle config
it outputs something like:
Set for the current user (/Users/user/.bundle/config):
"--with-cppflags=-I/usr/local/opt/openssl/include"
In the config file you can check your config setting.
If there's no anything strange like:
BUNDLE_PATH: vendor/cache
You can easily remove vendor/cache directory and run bundle install again
In other way just remove the config variable from the file and repeat ^^
P.S. If you met gems storing under your project. It's probably previous developers worked with private repos and to avoid problems with deploy and private repositories, they solved to store the gems under project directory. So just make sure you will not break your deploy after removing the gems dir.
Bundler 1.2 has support for :git and :path but it has to be explicitly enabled like this
bundle package --all

How to unpackage gems in a Rails app?

What is the opposite of $ bundle package vendor/cache?
I want to unpackage the gems. It seems there is something wrong with it, that every time I run bundle I get a multi_json-1.0.3 directory in my Rails app.
After running bundle in the command line, at the end it tells me "Your bundle is complete! It was installed into ./multi_json-1.0.3".
All that command does is place the gem code inside vendor/cache. If you want to remove it just delete the folder for multi_json, it should be easy to find.

Resources