Other setup options
If you don’t want to use Docsy as a Hugo Module (for example if you do not want to install Go) but still don’t want to copy the theme files into your own repo, you can use Docsy as a Git submodule. Using submodules also lets Hugo use the theme files from the Docsy repo, though is more complicated to maintain than the Hugo Modules approach. This is the approach used in older versions of the Docsy example site, and is still supported. If you are using Docsy as a submodule but would like to migrate to Hugo Modules, see our migration guide.
Alternatively if you don’t want Hugo to have to get the theme files from an external repo (for example, if you want to customize and maintain your own copy of the theme directly, or your deployment choice requires you to include a copy of the theme in your repository), you can clone the files directly into your site source.
Finally, you can install Docsy as an NPM package.
This guide provides instructions for all of these options, along with common prerequisites.
Prerequisites
Install Hugo
You need a
recent extended version (we
recommend version 0.158.0 or later) of
Hugo to do local builds and previews of sites (like this
one) that use Docsy. If you install from the release page, make sure to get the
extended Hugo version, which supports
SCSS; you
may need to scroll down the list of releases to see it.
For comprehensive Hugo documentation, see gohugo.io.
On Linux
If you’ve already installed Hugo, check your version:
hugo version
If the result is 0.158.0 or earlier, or if you don’t see
Extended, you’ll need to install the latest version. You can see a complete
list of Linux installation options in
Install Hugo. The following shows you
how to install Hugo from the release page:
Go to the Hugo releases page.
In the most recent release, scroll down until you find a list of Extended versions.
Download the latest extended version.
Create a new directory:
mkdir hugoExtract the files you downloaded to
hugo.Switch to your new directory:
cd hugoInstall Hugo:
sudo install hugo /usr/bin
On macOS
Install Hugo using Brew.
Hugo-extended NPM package
You can install Hugo as an NPM module using hugo-extended:
npm install hugo-extended --save-dev
Node: Get the latest LTS release
If you have Node installed already, check your version of Node. For example:
node -v
Install or upgrade your version of Node to the active LTS release. We recommend using nvm to manage your Node installation (Linux command shown):
nvm install --lts
Install PostCSS (optional)
See Install PostCSS.
Option 1: Docsy as a Git submodule
For a new site
To create a new site and add the Docsy theme as a Git submodule, run the following commands:
Create the site:
hugo new site myproject cd myproject git initFollow the instructions below for an existing site.
For an existing site
To add the Docsy theme to an existing site, run the following commands from your project’s root directory:
Install Docsy as a Git submodule:
git submodule add https://github.com/google/docsy.git themes/docsy cd themes/docsy git checkout v0.15.1-devTo work from the development version of Docsy (not recommended), run the following command instead:
git submodule add --depth 1 https://github.com/google/docsy.git themes/docsyAdd Docsy as a theme, for example:
echo 'theme: docsy/theme' >> hugo.yamlTipAs of Hugo 0.110.0, the default config base filename was changed to
hugo.*fromconfig.*. If you are using hugo 0.110+, consider renaming yourconfig.*tohugo.*.Get Docsy dependencies:
(cd themes/docsy && npm run postinstall)(Optional but recommended) To avoid having to repeat the previous step every time you update Docsy, consider adding NPM scripts like the following to your project’s
package.jsonfile:{ "...": "...", "scripts": { "get:submodule": "git submodule update --init --depth 1", "_prepare:docsy": "cd themes/docsy && npm run postinstall", "prepare": "npm run get:submodule && npm run _prepare:docsy", "...": "..." }, "...": "..." }Every time you run
npm installfrom your project root, thepreparescript will fetch the latest version of Docsy and its dependencies.
From this point on, build and serve your site using the usual Hugo commands, for example:
hugo serve
Option 2: Clone the Docsy theme
If you don’t want to use submodules (for example, if you want to customize and
maintain your own copy of the theme directly, or your deployment choice requires
you to include a copy of the theme in your repository), you can clone the theme
into your project’s themes subdirectory.
To clone Docsy at v0.15.1-dev into your project’s themes folder, run
the following commands from your project’s root directory:
cd themes
git clone -b v0.15.1-dev https://github.com/google/docsy
cd docsy
npm run postinstall
As with the submodule option, set
theme: docsy/theme in your site configuration.
To work from the development version of Docsy (not recommended unless, for
example, you plan to upstream changes to Docsy), omit the
-b v0.15.1-dev argument from the clone command above.
Then consider setting up an NPM prepare script, as documented in Option 1.
For more information, see Theme Components on the Hugo site.
Option 3: Docsy as an NPM package
You can use Docsy as an NPM module as follows:
Create your site and specify Docsy as the site theme:
hugo new site --format yaml myproject cd myproject echo "theme: docsy/theme\nthemesDir: node_modules" >> hugo.yamlInstall Docsy:
npm init -y npm install --save-dev google/docsy#semver:v0.15.1-dev --omit=peerHugo install tipYou can install Docsy’s officially supported version of Hugo using NPM at the same time as Docsy. Just omit the
--omitflag from the command above.Build or serve your new site using the usual Hugo commands, specifying the path to the Docsy theme files. For example, build your site as follows:
$ hugo Start building sites … ...
As an alternative to specifying a themesDir, on some platforms, you can
instead create a symbolic link to the Docsy theme directory as follows (Linux
commands shown, executed from the site root folder):
mkdir -p themes
pushd themes
ln -s ../node_modules/docsy
popd
Preview your site
To preview your site locally:
cd myproject
hugo server
By default, your site will be available at http://localhost:1313. For common issues, see Troubleshooting.
You may get Hugo errors for missing parameters and values when you try to build your site. This is usually because you’re missing default values for some configuration settings that Docsy uses - once you add them your site should build correctly. You can find out how to add configuration in Basic site configuration - we recommend copying the example site configuration even if you’re creating a site from scratch as it provides defaults for many required configuration parameters.
What’s next?
- Add some basic site configuration
- Add content and customize your site
- Get some ideas from our Example Site and other Examples and templates.
- Publish your site.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.