how to install NodeJS and NPM<\/a>.<\/p>\r\n\r\n\r\n\r\n$ curl -sL https:\/\/deb.nodesource.com\/setup_14.x | sudo -E bash -<\/pre>\r\n\r\n\r\n\r\nOnce completed, we need to download the package information from the newly added source above.<\/p>\r\n\r\n\r\n\r\n
$ sudo apt update<\/pre>\r\n\r\n\r\n\r\nNext, run the following command to finally install NodeJS and NPM.<\/p>\r\n\r\n\r\n\r\n
$ sudo apt install nodejs<\/pre>\r\n\r\n\r\n\r\nNodeJS and NPM have been successfully installed, you can check the installed version using this command:<\/p>\r\n\r\n\r\n\r\n
$ node -v; npm -v<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 4. Install Gatsby-CLI<\/span><\/h2>\r\n\r\n\r\n\r\nGatsby CLI is the main entry point for getting up and running the Gatsby application. It is packaged as an executable that can be used globally. We can install Gatsby CLI via npm.<\/p>\r\n\r\n\r\n\r\n
$ sudo npm install -g gatsby-cli<\/pre>\r\n\r\n\r\n\r\nTo check the installed version of Gatsby CLI, run this command:<\/p>\r\n\r\n\r\n\r\n
$ gatsby --version<\/pre>\r\n\r\n\r\n\r\nNow, let’s create a new Gatsby website, you can replace “gatsby_site<\/strong>” with any name you like.<\/p>\r\n\r\n\r\n\r\n$ gatsby new gatsby_site<\/pre>\r\n\r\n\r\n\r\nWait for a few moments, and a new “gatsby_site” directory is created.<\/p>\r\n\r\n\r\n\r\n <\/figure>\r\n\r\n\r\n\r\n <\/p>\r\n\r\n\r\n\r\n
Invoke the command below to develop Gatsby and run it.<\/p>\r\n\r\n\r\n\r\n
$ cd gatsby_site\r\n$ gatsby develop -H 0.0.0.0<\/pre>\r\n\r\n\r\n\r\n <\/figure>\r\n\r\n\r\n\r\n You should be able to access your Gatsby site at http:\/\/YOUR_SERVER_IP_ADDRESS:8000<\/code>, press CTRL + C if you want to stop it.<\/p>\r\n\r\n\r\n\r\nNow, let’s build our Gatsby website:<\/p>\r\n\r\n\r\n\r\n
$ gatsby build<\/pre>\r\n\r\n\r\n\r\nThe gatsby build<\/code> command is a part of the Gatsby CLI. Run gatsby build <\/code>command to create a production-ready version of your site when you are ready to publish your site. You can also deploy your Gatsby website to GitHub to set up a CI\/CD (Continuous Integration and Continuous Deployment) pipeline.<\/p>\r\n\r\n\r\n\r\n <\/figure>\r\n\r\n\r\n\r\n<\/span>Step 5. Install PM2<\/span><\/h2>\r\n\r\n\r\n\r\nProcess Manager (PM2) will allow you to keep applications alive forever, reload them without downtime, and facilitate common system admin tasks. Invoke the command below to install PM2 on your Ubuntu 20.04 globally.<\/p>\r\n\r\n\r\n\r\n
$ sudo npm install pm2 -g<\/pre>\r\n\r\n\r\n\r\nAfter installing PM2, we can run these commands to start our Gatsby website on port 8000.<\/p>\r\n\r\n\r\n\r\n
$ cd ~\/gatsby-site $ pm2 start gatsby --name mygatsby -- serve -p 8000<\/pre>\r\n\r\n\r\n\r\n <\/figure>\r\n\r\n\r\n\r\n