Building and testing your site locally, on your own computer, makes it easier to develop and maintain it. It also helps to keep your git history cleaner, with fewer and more meaningful commits. To do so, you will need to install a matching Jekyll toolchain on your machine. There are many ways to do this, and no one best way.
First, some references. Take a look at Jekyll's installation instructions. BUT make sure you install the correct versions, starting with Ruby. GitHub's instructions for testing locally reference the Jekyll docs and expand on them, but watch out for differences between GitHub Pages and Git Pages. There is a github-pages gem that you can use to get the correct gem versions.
Here are some general guidelines and tips.
One Environment or Many?
The tools you choose may depend on whether you wish to isolate the build environment for your site, or if you are comfortable having one environment for everything. One environment is simpler. Isolated environments are more flexible.
Ruby
You must use a particular version of Ruby to ensure everything will work. Don't mess with the Ruby version already installed on your machine. Choose a Ruby version manager such as chruby or rbenv. For easier isolation, you'll want to use rbenv. Get this working before you continue.
Jekyll
Simply install the github-pages gem to set up a global, non-isolated build environment.
gem install github-pages
Or for better isolation, use bundler. For that you'll need to create a Gemfile that looks something like this:
source "https://rubygems.org" ruby "3.3.4" gem "github-pages"
Then install the same gems as above using bundler.
bundle install
Build and Run
Run Jekyll on your site to build it and launch a test server.
jekyll serve
or
bundle exec jekyll serve
Point your browser to the local URL that Jekyll provides and see your creation!