Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 1347 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to install a gem or update RubyGems if it fails with a permissions error

#21
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`][1]

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 ##

1. Username
2. 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.


[1]:

[To see links please register here]

Reply

#22
give the user $whoami to create somethin in those folder

sudo chown -R user /Library/Ruby/Gems/2.0.0
Reply

#23
Tested on MacOS Mojave WITH SUCCESS:

1. Uninstall all your old ruby versions (let's say you have 2.00 and 2.3.0):

`$ rvm uninstall 2.0.0`

`$ rvm uninstall 2.3.0`

2. Install brand new ruby version:

`$ brew install ruby`

3. Set a default alias to your version:

`$ rvm alias create default ruby`

4. Reboot your system because this is the safest way your computer loads the new ruby version, recently installed.

AFTER you done above procedure, you can successfully run any `gem` command.
Reply

#24
`sudo chown -R $USER /Library/Ruby/Gems/`
Reply

#25
This will fix the issue on MacOS Mojave and Catalina in a clean way:

``` sh
brew install ruby
```

Then set `GEM_HOME` to your user directory. On the terminal:

- `Bash`:

``` sh
echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc
echo 'export GEM_HOME=$HOME/gems' >> ~/.bashrc
echo 'export PATH=$HOME/gems/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
```

- OR if on `Zsh`:

```sh
echo '# Install Ruby Gems to ~/gems' >> ~/.zshrc
echo 'export GEM_HOME=$HOME/gems' >> ~/.zshrc
echo 'export PATH=$HOME/gems/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
```


Reply

#26
You need to correct your paths.

To determine if this fix will work, run the following:

```sh
which gem
```

This should output a directory you do not have permissions to:

```none
/usr/bin/gem
```

To fix this perform the following steps:

1. Determine the path you need to copy to your profile:

```sh
rbenv init -
```

The first line of the output is the line you need to copy over to your profile:

```bash
export PATH="/Users/justin/.rbenv/shims:${PATH}" #path that needs to be copied
source "/usr/local/Cellar/rbenv/0.4.0/libexec/../completions/rbenv.zsh"
rbenv rehash 2>/dev/null
rbenv() {
typeset command
command="$1"
if [ "$#" -gt 0 ]; then
shift
fi

case "$command" in
rehash|shell)
eval `rbenv "sh-$command" "$@"`;;
*)
command rbenv "$command" "$@";;
esac
}
```

2. Copy the path to your profile and save it.

3. Reload your profile (`source ~/.zshenv` for me).

4. Run `rbenv rehash`.

Now when you run `which gem` you should get a local path that you have permissions to:

```none
/Users/justin/.rbenv/shims/gem
```
Reply

#27
As pointed out by bobbdelsol, rehash worked for me :

```none
==> which ruby
/usr/bin/ruby

==> rbenv install 1.9.3-p551
Downloading ruby-1.9.3-p551.tar.bz2...
->

[To see links please register here]

Installing ruby-1.9.3-p551...
Installed ruby-1.9.3-p551 to /Users/username/.rbenv/versions/1.9.3-p551


==> which ruby
/Users/username/.rbenv/shims/ruby

==> which gem
/Users/username/.rbenv/shims/gem

==> gem install compass
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.


==> ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]


==> rbenv global 1.9.3-p551


==> ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]


==> rbenv global 1.9.3-p551


==> rbenv rehash


==> ruby -v
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-darwin15.4.0]


==> gem install compass
Fetching: sass-3.4.22.gem (100%)
Fetching: multi_json-1.11.3.gem (100%)
Fetching: compass-core-1.0.3.gem (100%)
Fetching: compass-import-once-1.0.5.gem (100%)
Fetching: chunky_png-1.3.5.gem (100%)
Fetching: rb-fsevent-0.9.7.gem (100%)
Fetching: ffi-1.9.10.gem (100%)
Building native extensions. This could take a while...
Fetching: rb-inotify-0.9.7.gem (100%)
Fetching: compass-1.0.3.gem (100%)
Compass is charityware. If you love it, please donate on our behalf at

[To see links please register here]

Thanks!
Successfully installed sass-3.4.22
Successfully installed multi_json-1.11.3
Successfully installed compass-core-1.0.3
Successfully installed compass-import-once-1.0.5
Successfully installed chunky_png-1.3.5
Successfully installed rb-fsevent-0.9.7
Successfully installed ffi-1.9.10
Successfully installed rb-inotify-0.9.7
Successfully installed compass-1.0.3
9 gems installed
Installing ri documentation for sass-3.4.22...
Installing ri documentation for multi_json-1.11.3...
Installing ri documentation for compass-core-1.0.3...
Installing ri documentation for compass-import-once-1.0.5...
Installing ri documentation for chunky_png-1.3.5...
Installing ri documentation for rb-fsevent-0.9.7...
Installing ri documentation for ffi-1.9.10...
Installing ri documentation for rb-inotify-0.9.7...
Installing ri documentation for compass-1.0.3...
Installing RDoc documentation for sass-3.4.22...
Installing RDoc documentation for multi_json-1.11.3...
Installing RDoc documentation for compass-core-1.0.3...
Installing RDoc documentation for compass-import-once-1.0.5...
Installing RDoc documentation for chunky_png-1.3.5...
Installing RDoc documentation for rb-fsevent-0.9.7...
Installing RDoc documentation for ffi-1.9.10...
Installing RDoc documentation for rb-inotify-0.9.7...
Installing RDoc documentation for compass-1.0.3...
```
Reply

#28
You can change `GEM_HOME`. You have also under your home directory a gem folder to check it use

```
$ gem env
```
result is as follows. Unrelated parts are omitted.
```
...
- GEM PATHS:
- /Users/xxx/.gem/ruby/2.6.0
- /Library/Ruby/Gems/2.6.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0
...

```
You can use your `/Users/xxx/.gem/ruby/2.6.0` folder.

```
vim ~/.bash_profile
```
add the following line
```
export GEM_HOME=~/.gem/ruby/2.6.0/
```
After that you can use
```
source ~/.bash_profile
```
Reply

#29
The issue for me was that I switched from zshell to bash earlier and was not logged in:

```bash
/bin/bash --login
```

Although I had rvm installed, it was not able to switch to my newly rvm-installed ruby version and was still trying to use the default Mac-installed ruby binary. Hence my confusion (user error!!!) and the continued permissions issues...
Reply

#30
A 2021 solution (using rvm):

If you type `which ruby` in terminal, and it shows `/usr/bin/ruby`, you can try this solution.

1. install rvm

```sh
curl -L

[To see links please register here]

| bash -s stable
```

2. install ruby using rvm

```sh
rvm install "ruby-3.0.0"
```

3. use your installed version of ruby

```sh
rvm use ruby-3.0.0
```

4. type `which ruby` again, which will show `/Users/mac_user_name/.rvm/rubies/ruby-3.0.0/bin/ruby`.

It's a new path to use ruby.

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through