Older and wiser
Don't do what I say here, just know to be wary any time you use sudo
. You probably want to use something like rbenv
to isolate whatever work you're doing.
a way
learn about chown
I don't know if you like the command line, but this will make working on any project with any tool that installs packages to your system a breeze.
chown
as far as I can tell, stands for change ownership.
The reason I came looking for this answer is because gem install
threw this error at me today:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.9.1 directory.
This is a perfect opportunity to use chown
. You see Ruby has given us the directory it needs access to, and it seems like it's a directory it will use pretty often.
In this case, there are only three things one needs to know to solve the problem, but chown
is much more powerful, and grants you a lot more flexibility than I will demonstrate now. Please refer to the source at the bottom for more information.
The Two Things
- Username
- Directory
If you're in a shell finding the username is easy. Just look at the prompt. Mine looks like:
breadly@breadly-desktop:~\Desktop
The current user is just the name before the @
. We know the directory from the error messages, but you have two choices. You can either limit your permission to the current version by using ../gems/1.9.1
, or give yourself write permission for gems of all version by using ../gems
.
The command to actually change ownership would look like this.
chown -R $(whoami) /absolute/path/to/directory
The -R
is known as a flag and the -R
flag typically tells a command to do something recursively, or in other words perform the command on every thing that is contained in the directory, and all the things contained in the directories contained within, and so on till there isn't anything else.
sudo chown -R $USER /Library/Ruby/Gems/
– vaskort