
Are you interested in building your own fast and efficient website? Hugo is one of the best tools out there for creating static websites. In this tutorial, I’ll show you how to get Hugo up and running on your Windows computer using Chocolatey and Command Prompt (CMD). Don’t worry if you’re new to all this—I’ll walk you through each step!
What is Hugo?
Hugo is a static site generator, which means it takes content (like blog posts, pages, etc.) and turns it into a website. It’s incredibly fast, flexible, and perfect for beginners who want to get a website up and running quickly without much hassle.
What is Chocolatey?
Chocolatey is a package manager for Windows, similar to an app store for software. It helps you install, manage, and update software easily using commands in the Command Prompt.
Let’s get started with installing Hugo using Chocolatey. It might sound technical, but I’ll guide you through it step by step.
Step 1: Install Chocolatey
1.1 Open Command Prompt as Administrator
Press Win + X
and choose Command Prompt (Admin). If you don’t see it, search for “Command Prompt” in the Start menu, right-click, and choose Run as administrator.
1.2 Install Chocolatey
Once Command Prompt is open, you can install Chocolatey by typing the following command and pressing Enter:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
1.3 Verify Installation
To make sure Chocolatey is installed correctly, close and reopen Command Prompt and type:
choco --version
If you see the version number, that means Chocolatey is installed and ready to go!
Step 2: Install Hugo Using Chocolatey
2.1 Install Hugo
In Command Prompt, type the following command and press Enter:
choco install hugo -confirm
Chocolatey will automatically download and install Hugo. It’s that simple!
2.2 Verify Hugo Installation
Once the installation is complete, let’s check if Hugo is ready. Type this command:
hugo version
You should see something like this:
Hugo Static Site Generator v0.82.0/extended windows/amd64 BuildDate: unknown
This confirms that Hugo is installed and working.
Step 3: Create a New Hugo Site
3.1 Create a Site
Navigate to the folder where you want to create your website. For example, you could create it on your desktop:
cd C:\Users\YourUsername\Desktop
Replace YourUsername
with your actual username. Then, run this command to create a new Hugo site:
hugo new site my-site
This will create a new folder called my-site
, which contains the basic structure of your website.
3.2 Add a Theme to Your Site
One of the best things about Hugo is its themes. They make it super easy to customize your website’s look and feel. To add a theme, you can visit Hugo Themes, choose one you like, and follow the instructions for adding a theme. Most themes can be added by running a command like this:
git init
git submodule add https://github.com/some/theme.git themes/mytheme
Be sure to replace https://github.com/some/theme.git
with the URL of the theme you want to use.
3.3 Add Content to Your Site
Let’s add some content! Hugo uses markdown files to create pages and posts. To create a new post, type:
hugo new posts/my-first-post.md
This will create a markdown file for your first post. Open that file in any text editor (like Notepad or Visual Studio Code), and add your content!
Step 4: Build and Preview Your Site Locally
4.1 Build Your Site
To generate your static site, type:
hugo
This command will build your site and place the generated files into the public
folder inside your Hugo project.
4.2 Preview Your Site Locally
You can preview your site before publishing it by running:
hugo server
This will start a local server, and you can view your site in your browser by going to:
http://localhost:1313
Step 5: Publish Your Site
Once you’re happy with your site, you can publish it. Several ways to host your Hugo site are available, like GitHub Pages or Netlify.
Conclusion
Congrats! You’ve successfully installed Hugo, created a new site, and previewed it on your local machine—all with Command Prompt. It’s a simple process, and now you can start customizing your site and adding more content.
Note point
You will get an error message while installing so please follow this step to resolve this error
The error message you’re seeing occurs because the command Set-ExecutionPolicy
is a PowerShell command, and you’re trying to run it in Command Prompt (CMD), which doesn’t recognize PowerShell-specific commands.
To fix this issue, you need to run the command in PowerShell, not CMD.
Here’s what you can do:
- Open PowerShell as Administrator:
- Press
Win + X
, then select Windows PowerShell (Admin).
- Press
- Run the Installation Command in PowerShell: Now, paste the installation command in the PowerShell window:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
- After running this command, Chocolatey will be installed on your system.
Once Chocolatey is installed, you can return to Command Prompt (CMD) for the rest of the steps.
Thanks!