Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gem dependencies are not fully documented in the ReadMe #148

Open
verachell opened this issue Jun 21, 2023 · 11 comments
Open

Gem dependencies are not fully documented in the ReadMe #148

verachell opened this issue Jun 21, 2023 · 11 comments

Comments

@verachell
Copy link

This relates only to the documentation.

As a beginner/noob, I was struggling to get Camping working on my local machine. I followed the installation instructions and installed the gems camping, markaby, and activerecord. I then used the homepage.rb example but got errors when I typed camping homepage.rb (error descriptions below). After looking at the Gemfile for Camping, it seems there are other gem dependencies needed besides the ones mentioned in the ReadMe. I already happened to have some of these installed on my machine but not all. This indeed proved to be the solution - after installing the remaining gems mentioned in the Gemfile, the homepage.rb worked perfectly.

Other beginners might also be encountering this problem and not realize that there are other gems needed besides the ones mentioned in the ReadMe.

Perhaps the ReadMe could include something like this to make it more beginner-friendly:

Besides camping and markaby, you'll also need the following gems if you don't already have them installed: mab, rake, rackup, rack, and rack-session.

Note: for rackup and rack, it's best to install rackup first and then rack. Otherwise you may get a warning message about rackup conflicting with rack.

@verachell
Copy link
Author

This is a sort of appendix to the info I gave above in my comment on this issue. Here are the errors I was getting when I tried to run camping homepage.rb before installing the extra gems needed:

<internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:160:in `require': cannot load such file -- rack/server (LoadError)
	from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
	from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:149:in `require'
	from /var/lib/gems/3.0.0/gems/camping-2.1.532/lib/camping/server.rb:27:in `<module:Camping>'
	from /var/lib/gems/3.0.0/gems/camping-2.1.532/lib/camping/server.rb:26:in `<top (required)>'
	from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /var/lib/gems/3.0.0/gems/camping-2.1.532/bin/camping:6:in `<top (required)>'
	from /usr/local/bin/camping:25:in `load'
	from /usr/local/bin/camping:25:in `<main>'
<internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- rack/server (LoadError)
	from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /var/lib/gems/3.0.0/gems/camping-2.1.532/lib/camping/server.rb:27:in `<module:Camping>'
	from /var/lib/gems/3.0.0/gems/camping-2.1.532/lib/camping/server.rb:26:in `<top (required)>'
	from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from <internal:/usr/lib/ruby/vendor_ruby/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /var/lib/gems/3.0.0/gems/camping-2.1.532/bin/camping:6:in `<top (required)>'
	from /usr/local/bin/camping:25:in `load'
	from /usr/local/bin/camping:25:in `<main>'

@karloscarweber
Copy link
Member

I love this! Thank you so much.

Indeed there are more dependencies for Camping than are mentioned directly. It's recommended to install camping via bundler, and to run via bundler.

I've opened a PR to make these changes to the Readme and will merge this today.

@karloscarweber
Copy link
Member

I've opened a PR that should solve this issue. The feature branch with the updated README can be found here, before it's merged into Master.

@verachell
Copy link
Author

Oh wonderful! I didn't know about bundler. Thank you, I looked at your updated README, it's now nice and clear for beginners such as myself. I appreciate you writing the actual commands to use bundler to install Camping, because if someone had just told me to user bundler to install it, I would not have known what to do.

@karloscarweber
Copy link
Member

Please let me know if you need any more help.

I'll be releasing Camping 3.1 this week, then time will be dedicated to documentation for the project.

@verachell
Copy link
Author

Thanks! I for the sake of completeness, I tried Bundler but unfortunately it complained about needing write permissions for /var/lib/gems/[...] since that directory is owned by root. I tried bundler as sudo (sudo bundle install) but it said bundler shouldn't be run as root. BTW it's also possible that I didn't have the right files in my camping directory to begin with. I downloaded the Gemfile for camping. Was I supposed to download other files as well, for use with Bundler?

This problem is specific only to trying to install camping with bundler. If I install it via just installing the individual gems it needs, it works fine. Don't worry about this problem if it's something that will become clear in the documentation for Camping 3.1, or if it's an issue specific to running bundler (as opposed to something more directly related to Camping).

@karloscarweber
Copy link
Member

Let me help you diagnose this issue.

Which platform are you using to install Camping? Is it linux, MacOS, or Windows?

Are you using a Ruby version manager at all?

Could you upload or share a copy of your working directory on Github so that I can inspect and hope to diagnose the issue?

Also Is it possible to upload the error that you're experiencing?

Please share as much detail as you can, I'm ready to help you solve the issue completely.

@verachell
Copy link
Author

Oh thank you! Going through the process of answering your questions was incredibly helpful for me as I think in doing so, I have figured out the problem. The TL;DR summary of all the info below is at least for the older versions of Ruby and Camping that I was working with, bundler seems to work but gives some warnings that made me think it wasn't working, and results in a file owned by root in my non-root directory (not sure if that's an issue or not).

Also, I will be updating to new versions of Ruby and camping because it turned out I was using older versions of both.

Here are answers to your questions:

Which platform are you using to install Camping? Is it linux, MacOS, or Windows?

Linux

Are you using a Ruby version manager at all?

No, but I realize that I need to use one, so that will be my next step. My current version of Ruby is 3.0.2.107. I tried to update it using the Synaptic Package Manager, but sadly that was already the most recent version of Ruby in the Synaptic Package Manager. So I will install rvm or something like that so I can get a more recent version of Ruby.

Related to this, I realized I have been using Camping v 2.1.532 instead of your most recent release of Camping, sorry. I tried to update the Camping gem to get your most recent version using gem update camping but unfortunately my version of Ruby is too old (totally my fault, I need to use rvm to install a more recent version of Ruby). Here is the error message I get if I try to update Camping with my outdated version of Ruby:

gem update camping
Updating installed gems
Updating camping
ERROR:  Error installing camping:
	camping-3.1.3 requires Ruby version >= 3.1.2. The current ruby version is 3.0.2.107.
Nothing to update

I will update these shortly.

Could you upload or share a copy of your working directory on Github so that I can inspect and hope to diagnose the issue?

Yes, of course. It's at https://github.com/verachell/my-working-directory-for-camping

It uses the homepage.rb example given in the Camping repo documentation. If I'm missing any files that I should have added into my working directory, please let me know! I just have those 2 files in my working directory, that's it. The good news is that with the camping 2.1.532 gem installed via gem install (plus the other dependent gems also installed via gem install) then camping works fine. I just type camping homepage.rb in the command line of that working directory and the resultant page browsed at localhost works perfectly.

So that's the good news.

Also Is it possible to upload the error that you're experiencing?

Yes, definitely. In that working directory, if I type bundle install, this is what happens:

bundle install
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Using rake 13.0.6
Fetching ast 2.4.2
Fetching ansi 1.5.0

Retrying download gem from https://rubygems.org/ due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/var/lib/gems/3.0.0/cache/ast-2.4.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 (3/4): Bundler::PermissionError There was an error while trying to write to `/var/lib/gems/3.0.0/cache/ast-2.4.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 (2/4): Bundler::PermissionError There was an error while trying to write to `/var/lib/gems/3.0.0/cache/ansi-1.5.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 `/var/lib/gems/3.0.0/cache/ast-2.4.2.gem`. It is likely that you need to grant write permissions for that path.

Using builder 3.2.4

Using bundler 2.4.13
Retrying download gem from https://rubygems.org/ due to error (3/4): Bundler::PermissionError There was an error while trying to write to `/var/lib/gems/3.0.0/cache/ansi-1.5.0.gem`. It is likely that you need to grant write permissions for that path.
Fetching diff-lcs 1.5.0

Retrying download gem from https://rubygems.org/ due to error (4/4): Bundler::PermissionError There was an error while trying to write to `/var/lib/gems/3.0.0/cache/ansi-1.5.0.gem`. It is likely that you need to grant write permissions for that path.

.
.
.
There is a lot more in this error list, but it's all more or less similar. This is not surprising since write permissions on the gems (installed system-wide) are for root, not the non-root user who owns the working directory where the camping app is located. Here are the permissions for the root-owned gem directory:

ls -alt /var/lib/gems/3.0.0
total 52
drwxr-xr-x 137 root root  4096 Jun 24 21:17 gems
drwxr-xr-x   9 root root  4096 Jun 24 20:42 .
drwxr-xr-x  38 root root  4096 Jun 21 09:20 doc
drwxr-xr-x   2 root root 12288 Jun 21 09:19 specifications
drwxr-xr-x   2 root root 12288 Jun 21 09:19 cache
drwxr-xr-x   3 root root  4096 May 17 14:12 extensions
drwxr-xr-x   2 root root  4096 May 17 14:12 plugins
drwxr-xr-x   2 root root  4096 May 17 14:12 build_info
drwxr-xr-x   3 root root  4096 May 17 14:08 ..

By comparison, if I list the contents of my working directory, it looks like this:


ls -alt
total 16
drwxrwxr-x  2 family family 4096 Jun 24 21:00 .
-rw-rw-r--  1 family family  393 Jun 24 21:00 Gemfile
-rw-rw-r--  1 family family 1064 Jun 20 22:41 homepage.rb
drwxr-xr-x 11 family family 4096 Jun 20 22:25 ..

Realizing there is a permission issue going on, I then try to run bundle install with root permissions (sudo bundle install). Here is what happens in my working directory - it warns me against running Bundler as root:

sudo bundle install
Don't run Bundler as root. Installing your bundle as root will break this
application for all non-root users on this machine.

However, I then let it run anyway just to see what happened, and it wound up working in the end, but it produced a Gemfile.lock that was owned by root (in my non-root working directory):

ls -alt
total 20
drwxrwxr-x  2 family family 4096 Jun 24 23:24 .
-rw-r--r--  1 root   root   1366 Jun 24 23:24 Gemfile.lock
-rw-rw-r--  1 family family  393 Jun 24 21:00 Gemfile
-rw-rw-r--  1 family family 1064 Jun 20 22:41 homepage.rb
drwxr-xr-x 11 family family 4096 Jun 20 22:25 ..

The Gemfile.lock was still readable by the non-root user, so it's probably OK. Here is what the Gemfile.lock looks like:

cat Gemfile.lock
GEM
  remote: https://rubygems.org/
  specs:
    ansi (1.5.0)
    ast (2.4.2)
    builder (3.2.4)
    diff-lcs (1.5.0)
    ffi (1.15.5)
    kdl (1.0.3)
      simpleidn (~> 0.2.1)
    listen (3.8.0)
      rb-fsevent (~> 0.10, >= 0.10.3)
      rb-inotify (~> 0.9, >= 0.9.10)
    mab (0.0.3)
    minitest (5.18.1)
    minitest-hooks (1.5.0)
      minitest (> 5.3)
    minitest-reporters (1.6.0)
      ansi
      builder
      minitest (>= 5.0)
      ruby-progressbar
    parser (3.2.2.3)
      ast (~> 2.4.1)
      racc
    racc (1.7.1)
    rack (3.0.8)
    rack-session (2.0.0)
      rack (>= 3.0.0)
    rack-test (2.1.0)
      rack (>= 1.3)
    rackup (2.1.0)
      rack (>= 3)
      webrick (~> 1.8)
    rake (13.0.6)
    rb-fsevent (0.11.2)
    rb-inotify (0.10.1)
      ffi (~> 1.0)
    ruby-progressbar (1.13.0)
    ruby_parser (3.20.2)
      sexp_processor (~> 4.16)
    sexp_processor (4.17.0)
    simpleidn (0.2.1)
      unf (~> 0.1.4)
    tilt (2.2.0)
    unf (0.1.4)
      unf_ext
    unf_ext (0.0.8.2)
    unparser (0.6.8)
      diff-lcs (~> 1.3)
      parser (>= 3.2.0)
    webrick (1.8.1)
    zeitwerk (2.6.8)

PLATFORMS
  x86_64-linux

DEPENDENCIES
  kdl
  listen
  mab
  minitest (~> 5.0)
  minitest-hooks
  minitest-reporters
  parser
  rack
  rack-session
  rack-test
  rackup
  rake
  ruby_parser
  tilt
  unparser
  zeitwerk

BUNDLED WITH
   2.4.13

Ultimately, this seems to work, but gives a scary warning about running bundler as root, so maybe isn't really a problem after all. Thank you for bearing with me!

I need to get my versions of Ruby and camping up to date, and to do that I need to install a ruby version manager which I will do next. But at least for the older versions I was working with, bundler seems to work but gives some warnings that made me think it wasn't working.

@verachell
Copy link
Author

verachell commented Jun 25, 2023

Updating what happened after installing a ruby version manager and trying out new version of camping

I installed rbenv on my local machine (for whatever reason I couldn't get rvm to work on Linux Mint). I used the Gemfile from the Camping 3.1.1 release, and the homepage.rb example mentioned previously.

In this situation, bundle install worked fine locally, producing a Gemfile.lock with normal (non-root) user permissions. So this part is now solved and I can see the browsable web page created by homepage.rb, which is good.

However, when I move on and type bundle exec camping -e development, I get this error.

bundler: failed to load command: camping (/home/family/.rbenv/versions/3.1.2/bin/camping)
/home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/rubygems_integration.rb:308:in `block in replace_bin_path': can't find executable camping for gem camping. camping is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/rubygems_integration.rb:336:in `block in replace_bin_path'
	from /home/family/.rbenv/versions/3.1.2/bin/camping:25:in `<top (required)>'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/cli/exec.rb:58:in `load'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/cli/exec.rb:23:in `run'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/cli.rb:492:in `exec'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/cli.rb:34:in `dispatch'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/cli.rb:28:in `start'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/exe/bundle:37:in `block in <top (required)>'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /home/family/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.4.14/exe/bundle:29:in `<top (required)>'
	from /home/family/.rbenv/versions/3.1.2/bin/bundle:25:in `load'
	from /home/family/.rbenv/versions/3.1.2/bin/bundle:25:in `<main>'

In case this is of relevance, when I list gems, the camping gem version is 3.1.3

I don't see this issue as a big problem because I can still get camping to work just fine via the camping command (in this example, camping homepage.rb )

@karloscarweber
Copy link
Member

karloscarweber commented Jun 25, 2023

The issue I see is the Gemfile you're using has Camping's dependencies, but not Camping itself. If you Just add Camping to your Gemfile, then It's dependencies will be installed automatically. Try using this Gemfile:

# frozen_string_literal: true
source 'https://rubygems.org'

gem 'camping'
gem 'tilt'

group :test do
  gem 'minitest', '~> 5.0'
  gem 'minitest-reporters'
  gem 'rack-test'
  gem 'ruby_parser'
  gem 'minitest-hooks'
end

Now delete your Gemfile.lock and bundle install again.

It's fantastic that you're working with rbenv! This is great! Make sure you are on the latest version of Ruby. I think the expected behaviour is that each version of Ruby that you have will have its own gems, or versions of gems, scoped to the version of Ruby. So if you have Ruby 3.1.0 and install Ruby 3.2.0, then begin using 3.2.0 you'll need to install your gems again.

I'm saying this because the version of Camping that you use straight from the command line will be different from the bundler version of ruby. So you'll need to gem update camping to get camping updated. Then bundle install to have camping installed for your project.

Once that is done you'll be just a single step from getting it to work. Rename homepage.rb to camp.rb and then you should be able to run bundle exec camping -e development to get your server running with the latest version of camping.

I hope that clears up the last of the issues you're experiencing.

@verachell
Copy link
Author

Yes! Yes! It's working, yay....! :) I followed your instructions above exactly, and it worked perfectly. Thank you for all your advice, patience and help.

Make sure you are on the latest version of Ruby. I think the expected behaviour is that each version of Ruby that you have will have its own gems, or versions of gems, scoped to the version of Ruby. So if you have Ruby 3.1.0 and install Ruby 3.2.0, then begin using 3.2.0 you'll need to install your gems again.

This was excellent advice that is helpful to beginners such as myself. I was unaware that gems are scoped to the version of Ruby, that must be why I lost the camping gem before. And I wasn't aware that the version of camping from the command line could be different from the bundler one until you said.

Even more exciting, after doing bundle exec camping -e development with success, I also tried bundle exec camping -e production because my eventual goal is to use camping on a production server. I can attest that in production mode (but still on my local machine) the bits that had templates continued to work fine in production mode. And if I purposely typed in a page URL that didn't exist then the production mode came up with Internal Server Error (and not all the other info that comes up in development mode which we wouldn't want to leak out to the world on a production server). This is why I am so glad to now be able to run it via bundle exec. Thank you! I'm heading off to play more with camping now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants