In this tutorial I’ll show you the quickest and most reliable way to get Gatsby up and running on an Ubuntu 18.04 (Bionic Beaver) server.
Install Node.js, NPM and Build Essentials
There are a few ways to install Node.js and NPM on Ubuntu 18.04 but this is the one you want, and you can be certain it will install a version of Node.js and NPM that will run Gatsby. The commands below will use
curl to download the official PPA script, but you can replace
8.x with your preferred version.
cd ~ curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
Run the script under
sudo bash nodesource_setup.sh
This will add the PPA and the local package cache will be updated automatically. After running the setup script you can then install Node.js like this:
sudo apt install nodejs
Now check your Node.js version to make sure it works with:
And check NPM version too:
npm packages to work (compiling from source, for example) you’ll need the
sudo apt install build-essential
Now you have Node.js and NPM working you can move on to install Gatsby.
Install Git and Gatsby CLI
To install Gatsby you’ll first need to have the
git package installed:
sudo apt install git
The Gatsby CLI tool enables you to create new sites, and run commands for developing Gatsby sites. It’s a published
npm package you can easily install using the following command:
sudo npm install --global gatsby-cli
Check Gatsby installed properly with:
Now Gatsby is installed you can create your first Gatsby test site:
gatsby new hello-world https://github.com/gatsbyjs/gatsby-starter-hello-world
This command created a directory called
hello-world and downloaded the test site to it, you can now run the starter site with:
cd hello-world gatsby develop
Your Gatsby site is now running at
http://localhost:8000 and should output Hello world!
If you’re running Gatsby remotely you might want it on all IP addresses at port 80, do that with:
cd hello-world gatsby develop -H 0.0.0.0 -p 80
Now Gatsby will be accessible from your public IP on port 80.
I hope this tutorial helped you get Gatsby up and running quickly on Ubuntu 18.04 (Bionic Beaver) and if you have any comments or questions please leave them below.
Visit the Gatsby website for additional information.