"No such file or directory - getcwd" error on rubygems on Mac Os Lion

MacosRubygemsHeroku

Macos Problem Overview


I'm trying to launch a heroku console that uses rubygems but I keep getting this error:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:471:in `expand_path': No such file or directory - getcwd (Errno::ENOENT)
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:471:in `find_files'
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:470:in `map'
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:470:in `find_files'
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems.rb:1103
	from /usr/bin/heroku:9:in `require'
	from /usr/bin/heroku:9

I'm using Mac OS Lion 10.7.3. Any ideas on how to fix this? Thanks!

Macos Solutions


Solution 1 - Macos

Maybe the current working directory of the shell that's used to start your heroku process doesn't exist (maybe removed by another process, as in my case), and therefore getcwd throws an error.

Solution 2 - Macos

This happened to me. It turned out I had deleted the folder I was running the command in.

Solution 3 - Macos

I had that same issue.... running sudo gem update --system fixed the problem... give it a try.

Solution 4 - Macos

I had the same thing, just type cd in the terminal, then navigate back to where you were and it works.

Solution 5 - Macos

Tried starting the rails server in another console tab.

cd . solved it for me

Solution 6 - Macos

Faced a similar issue while setting up rails app locally.

The issue was that the server was running in a directory which i had removed from another terminal window to recreate the app.

Close terminal and do it again or go to some other directory and come back and do it...

Anything should work..It did for me.

Solution 7 - Macos

I encounter a same one, it happened when the working directory has actually been removed.

Solution 8 - Macos

This doesn't appear to be Heroku issue as something in your code is requiring this getcwd.

What happens if you run this application locally in production mode? Have you defined all of your dependencies for Heroku (either via a .gems file or Bundler)

Solution 9 - Macos

In my case, I was in a directory that had "unusual" characters in its name: /Volumes/Members/Finance & Accounting/-MC 2008, 7848/2020.

And also, I was in a remote directory, as Mac users will recognize.

I simply did push ~ and ran the command again, then did popd to get back to my remote directory with odd characters in the name.

It could be that gem is ill-behaved in the face of directory names containing whitespace, or it could be that it doesn't work on networked directories.

The bash built-in pwd worked just fine in the remote directory with the funny name.

This whole thing makes me a bit nervous about gem.

Solution 10 - Macos

solved for me

cd ..
cd -

you have to go back and return to current directory.

Solution 11 - Macos

as explained by gerardk you could try this before launching back heroku console

$ pwd #ie: /mywork
$ cd ..
$ cd [pwd] #ie: cd mywork

now go launch back heroku console

Solution 12 - Macos

This just happened to me while I was running a Sinatra app on my localhost and this is what I found.

Scenario: I'm using Git as my version control and I switched branches from development to master to merge my branches. After the merge, with an active server running, I made a minor html change which shouldn't have blown up the app and when I went to check the change in my broswer my "request" came back with OP's error - just to note this app isn't deployed to heroku.

My guess: I'm not familiar with the intricacies of Webbrick (or equivalent programs) but I'm guessing you had an active server running (like me) and it was was looking for specific file(s) in memory and when they were modified on a possible branch change or an important file was modified/deleted - Webbrick freaked out and didn't know where to find it/them and threw up this error.

I'm not sure what version control you're using but I know git is popular for heroku so I think this might have something to do with your issue.

Fixing the issue for myself was as simple as restarting the server, hope this helps future trouble shooters.

Solution 13 - Macos

I solved this problem by closing and restarting my terminal, setting the correct Ruby version in the new Terminal to

$ rvm use 2.1.1

(or whatever Ruby version is relevant to your program)

Solution 14 - Macos

Restart system fixed this problem in my case

Solution 15 - Macos

I worked around this error by shutting down the server, restarting my terminal, then restarting the server.

Solution 16 - Macos

sudo gem update --system (as Israfil Havilah mentioned) and rebooting the server (Ubuntu 16.04.6 LTS) helped me

Solution 17 - Macos

Ended up on this page from searching for the same error on AWS Elastic beanstalk.

The problem with getcwd is because EB is trying to repeat the deployment process endlessly. It changes the /var/app/staging directory before it is able to finish the current action. getcwd fails because the directory was already replaced. Try deploying a stable version or a sample app

Solution 18 - Macos

Make sure, you are not switching git branches. To me, it happened due to switching between GIT branches deleted my folder.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael Eilers SmithView Question on Stackoverflow
Solution 1 - MacosgerardkView Answer on Stackoverflow
Solution 2 - MacoskilojoulesView Answer on Stackoverflow
Solution 3 - MacosIsrafil HavilahView Answer on Stackoverflow
Solution 4 - MacosMirror318View Answer on Stackoverflow
Solution 5 - MacosChristianView Answer on Stackoverflow
Solution 6 - MacosVishnu NarangView Answer on Stackoverflow
Solution 7 - MacosDavid ZhangView Answer on Stackoverflow
Solution 8 - MacosNeil MiddletonView Answer on Stackoverflow
Solution 9 - MacosJan SteinmanView Answer on Stackoverflow
Solution 10 - MacosВладимир ЕфановView Answer on Stackoverflow
Solution 11 - MacosAizzat SuhardiView Answer on Stackoverflow
Solution 12 - MacosMTenView Answer on Stackoverflow
Solution 13 - MacosLa-comadrejaView Answer on Stackoverflow
Solution 14 - MacosMaciej.OView Answer on Stackoverflow
Solution 15 - MacosianrandmckenzieView Answer on Stackoverflow
Solution 16 - MacosPavel BabinView Answer on Stackoverflow
Solution 17 - MacosAlexander ParamonovView Answer on Stackoverflow
Solution 18 - MacosVahidView Answer on Stackoverflow