Currently on Ubuntu 22.04 desktop version and wanted to run ruby on rails app.
Current ruby version: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux] Rails version: Rails 7.1.2
I installed the rails app using rails new blog
and then when wanted to install gem files using bundle install
I faced this error:
ss@amin-desktop-ubuntu:~/blog$ bundle install
Fetching gem metadata from https://rubygems.org/.........
Fetching rake 13.1.0
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rake-13.1.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rake-13.1.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rake-13.1.0.gem`. It is likely that you need to grant write permissions for that path.
Fetching bigdecimal 3.1.5
Using concurrent-ruby 1.2.2
Using ruby2_keywords 0.0.5
Using connection_pool 2.4.1
Using minitest 5.20.0
Fetching mutex_m 0.2.0
Fetching base64 0.2.0
Using builder 3.2.4
Using erubi 1.12.0
Using racc 1.7.3
Using crass 1.0.6
Using rack 3.0.8
Using nio4r 2.7.0
Using websocket-extensions 0.1.5
Using zeitwerk 2.6.12
Using timeout 0.4.1
Using marcel 1.0.2
Using mini_mime 1.1.5
Fetching date 3.3.4
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/base64-0.2.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/mutex_m-0.2.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/date-3.3.4.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/base64-0.2.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/bigdecimal-3.1.5.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/mutex_m-0.2.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/base64-0.2.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/date-3.3.4.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/mutex_m-0.2.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/bigdecimal-3.1.5.gem`. It is likely that you need to grant write permissions for that path.
Fetching public_suffix 5.0.4
Fetching bindex 0.8.1
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/date-3.3.4.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/bigdecimal-3.1.5.gem`. It is likely that you need to grant write permissions for that path.
Fetching msgpack 1.7.2
Using bundler 2.4.10
Using matrix 0.4.2
Fetching regexp_parser 2.8.3
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/bindex-0.8.1.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/public_suffix-5.0.4.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/bindex-0.8.1.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/msgpack-1.7.2.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/bindex-0.8.1.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/public_suffix-5.0.4.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/regexp_parser-2.8.3.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/msgpack-1.7.2.gem`. It is likely that you need to grant write permissions for that path.
Fetching stringio 3.1.0
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/public_suffix-5.0.4.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/regexp_parser-2.8.3.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/msgpack-1.7.2.gem`. It is likely that you need to grant write permissions for that path.
Fetching io-console 0.7.1
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/regexp_parser-2.8.3.gem`. It is likely that you need to grant write permissions for that path.
Using webrick 1.8.1
Using thor 1.3.0
Fetching rexml 3.2.6
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/stringio-3.1.0.gem`. It is likely that you need to grant write permissions for that path.
Fetching rubyzip 2.3.2
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/stringio-3.1.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/io-console-0.7.1.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/stringio-3.1.0.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rexml-3.2.6.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/io-console-0.7.1.gem`. It is likely that you need to grant write permissions for that path.
Fetching websocket 1.2.10
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rubyzip-2.3.2.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/io-console-0.7.1.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rexml-3.2.6.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rubyzip-2.3.2.gem`. It is likely that you need to grant write permissions for that path.
Fetching sqlite3 1.7.0 (x86_64-linux)
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rubyzip-2.3.2.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rexml-3.2.6.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/websocket-1.2.10.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/websocket-1.2.10.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/websocket-1.2.10.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/sqlite3-1.7.0-x86_64-linux.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/sqlite3-1.7.0-x86_64-linux.gem`. It is likely that you need to grant write permissions for that path.
Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/sqlite3-1.7.0-x86_64-linux.gem`. It is likely that you need to grant write permissions for that path.
Bundler::PermissionError: There was an error while trying to write to `/usr/local/lib/ruby/gems/3.2.0/cache/rake-13.1.0.gem`. It is likely that you need to grant write permissions for that path.
/usr/local/lib/ruby/3.2.0/bundler/shared_helpers.rb:105:in `rescue in filesystem_access'
/usr/local/lib/ruby/3.2.0/bundler/shared_helpers.rb:102:in `filesystem_access'
/usr/local/lib/ruby/3.2.0/bundler/rubygems_integration.rb:483:in `block in download_gem'
/usr/local/lib/ruby/3.2.0/bundler/retry.rb:40:in `run'
/usr/local/lib/ruby/3.2.0/bundler/retry.rb:30:in `attempt'
/usr/local/lib/ruby/3.2.0/bundler/rubygems_integration.rb:474:in `download_gem'
/usr/local/lib/ruby/3.2.0/bundler/source/rubygems.rb:484:in `download_gem'
/usr/local/lib/ruby/3.2.0/bundler/source/rubygems.rb:446:in `fetch_gem'
/usr/local/lib/ruby/3.2.0/bundler/source/rubygems.rb:430:in `fetch_gem_if_possible'
/usr/local/lib/ruby/3.2.0/bundler/source/rubygems.rb:158:in `install'
/usr/local/lib/ruby/3.2.0/bundler/installer/gem_installer.rb:54:in `install'
/usr/local/lib/ruby/3.2.0/bundler/installer/gem_installer.rb:16:in `install_from_spec'
/usr/local/lib/ruby/3.2.0/bundler/installer/parallel_installer.rb:156:in `do_install'
/usr/local/lib/ruby/3.2.0/bundler/installer/parallel_installer.rb:84:in `call'
/usr/local/lib/ruby/3.2.0/bundler/installer/parallel_installer.rb:67:in `call'
/usr/local/lib/ruby/3.2.0/bundler/installer.rb:244:in `install_in_parallel'
/usr/local/lib/ruby/3.2.0/bundler/installer.rb:201:in `install'
/usr/local/lib/ruby/3.2.0/bundler/installer.rb:89:in `block in run'
/usr/local/lib/ruby/3.2.0/bundler/process_lock.rb:19:in `rescue in lock'
/usr/local/lib/ruby/3.2.0/bundler/process_lock.rb:15:in `lock'
/usr/local/lib/ruby/3.2.0/bundler/installer.rb:71:in `run'
/usr/local/lib/ruby/3.2.0/bundler/installer.rb:23:in `install'
/usr/local/lib/ruby/3.2.0/bundler/cli/install.rb:62:in `run'
/usr/local/lib/ruby/3.2.0/bundler/cli.rb:261:in `block in install'
/usr/local/lib/ruby/3.2.0/bundler/settings.rb:131:in `temporary'
/usr/local/lib/ruby/3.2.0/bundler/cli.rb:260:in `install'
/usr/local/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/usr/local/lib/ruby/3.2.0/bundler/cli.rb:34:in `dispatch'
/usr/local/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/usr/local/lib/ruby/3.2.0/bundler/cli.rb:28:in `start'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.10/libexec/bundle:45:in `block in <top (required)>'
/usr/local/lib/ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-2.4.10/libexec/bundle:33:in `<top (required)>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
An error occurred while installing rake (13.1.0), and Bundler cannot continue.
In Gemfile:
importmap-rails was resolved to 2.0.1, which depends on
railties was resolved to 7.1.2, which depends on
rake
I tried to do it using sudo
but Rails doesn’t allow me
How do we fix this issue?
2
Answers
To fix this issue you have to change your path of bundle install using this command:
I used the
~/Documents
path that doesn't need written permissionyou can use whatever you want.
Try to give you write permission to the gems file with: