I am setting up Jekyll on my computer based on the information given on Jekyll's homepage. Ruby 2.6.3 was installed via rbenv
.
In the first step I created a minimal Gemfile, containing only Jekyll
source "https://rubygems.org"
ruby "2.6.3"
group :base do
gem 'jekyll', '4.0.0'
end
I installed all gems via bundle install
and as far as I can see they have been installed properly. I verified it via
user@host:homepage> bundle info jekyll
* jekyll (4.0.0)
Summary: A simple, blog aware, static site generator.
Homepage: https://jekyllrb.com
Path: /Users/user/.gem/ruby/2.6.0/gems/jekyll-4.0.0
According to the tutorial I should now be able to run Jekyll via bundle exec jekyll serve
. If I now execute this command I alway get this error:
user@host:homepage> bundle exec jekyll serve
bundler: command not found: jekyll
Install missing gem executables with `bundle install`
Why can't Bundler find the installed gems?
I works only if run Bundler with the --path
option like this: bundle install --path vendor/bundle
. Then Bundler write also .bundle/config
with the following content:
---
BUNDLE_PATH: "vendor/bundle"
In this case it is clear that Bundler is able to find the installed gems.
But shouldn't Bundler not also be able to find the gems installed without an explicit path? I would like to download and to install gems only once and not per project.
I see two issues here to tackle.
Firstly on use of bundler.
The way bundler is meant to work is that when you clone a project you always run this from a project root.
bundle install --path vendor/bundle
That is all over projects and tutorials.
On subsequent install commands in the same project, navigate to the project root and run
bundle install
Bundle uses the config file created before. this should not be in vesion control as it looks different for dev and prod deploys (prod deploy should have a frozen attribute)
If you omit the path the first time you'll install to a default directory. I don't know where this is but it will fail with an explanation unless you use sudo
- which you probably want to avoid. The error message explains it well.
The second issue is how to install a gem once and reuse it across projects. I only do this for two gems. Both are shown here. Note the lack of bundle install and also the addition of the use flag otherwise there can be errors which need sudo.
gem install bundler jekyll --user-install
Now you can run jekyll
from anywhere without bundle exec.
And you can run bundle from anywhere which probably had already.
BTW I've not seen Ruby version in Gemfile before. That's not needed and may be restrictive on other machines. Follow a template project or a jekyll tutorial for setting up Gemfile