Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accidentally deleted many hidden files with "git clean -fd" and now I cannot install Ruby

So I really messed up on this one..... I was working on a rails application and wanted to revert back to a previous commit. I opened a new shell and forgot to cd into my projects folder, so I ran "git reset --hard" and then "git clean -fd" in my user directory. I noticed before everything was gone, but here is what got deleted:

bash-3.2$ git clean -fd
Removing .CFUserTextEncoding
Removing .Trash/
Removing .Xauthority
Removing .adobe/
Removing .bash_history
Removing .bash_profile
Removing .bundle/
Removing .config/
Removing .cups/
Removing .dropbox/
Removing .fontconfig/
Removing .gem/
Removing .gitconfig
Removing .guard_history
Removing .heroku/
Removing .irb-history
Removing .irb_history
Removing .lesshst
Removing .macports/
^C

I was able to save my project in that shell, but I (now realized stupidly) thought restarting my computer would be best once I realized my rails and bundle commands were not working in another shell. Unfortunately I lost that working shell which I through researching realize would have helped.

What is done is done, and I am trying to fix everything, but something I cannot get right is installing ruby. I am using rbenv to install ruby but even after installing it, it won't register with in any shell:

-bash-3.2$ rbenv local
2.1.1
-bash-3.2$ ruby -v
-bash: ruby: command not found

I am a bit inexperienced when it comes to the terminal and I am freaking out. I am wondering if I should restore factory settings. My important pictures and documents are backed up but I don't use time machine.

I don't know if it is just ruby which is the problem, so far nothing else has been an issue, but I would appreciate any help solving the problem!

EDIT

So I realize now that the issue was deleting my bash_profile which has had all sorts of knock on effects. I really don't know how to fix or reset it....I am trying to uninstall everything and reinstall it but I am having trouble figuring out what. I tried installing ruby via mac ports, which worked, but it was not sending the message to rbenv.

like image 847
tommy-taco Avatar asked Nov 11 '22 03:11

tommy-taco


1 Answers

I suggest HomeBrew to install rbenv. It has worked better for me than MacPorts did.

This older post Modern Ruby Development (on Mac) is still very helpful.

The install for HomeBrew needs ruby, which will be a problem for you as you have lost ruby.

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

The rbenv lines you need in your .bash_profile, according to the rbenv install docs, are,

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Do not forget to say, source .bash_profile after editing the profile, or open a new terminal.

If your rbenv command is no longer available, you can install it directly from git with,

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

That is assuming the git command still works.

With the rbenv lines restored to your .bash_profile, you might be able to install a ruby with,

rbenv install 2.1.1

(rbenv install -l will list available versions. Any of the lines output from there can go after rbenv install.)

Finally, use rbenv global to set the default ruby to one of the rbenv installed ones.

rbenv global 2.1.1

You can view the current global ruby set for rbenv with,

rbenv global

As you know,

ruby -v

will get the version of the ruby that runs by default. You might not know that,

which ruby

will tell you where the shell finds that ruby command in your path.

like image 125
Douglas Lovell Avatar answered Nov 15 '22 04:11

Douglas Lovell