In this article, we’ll explain you how it is easy to install Next.js on Ubuntu 20.04.
- A Ubuntu 20.04 installed server.
- A root user access or normal user with administrative privileges.
Install Next.js on Ubuntu 20.04.
1. Keep the server Up to date
# apt update -y
# apt upgrade -y
2. Install build-essential
# apt-get install build-essential
3. Install required package
# apt install curl -y
4 . Install NodeJS and NPM
Add the latest stable release of NodeJS.
# curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash –
# sudo apt-get install nodejs
Verify the installations.
# node -v
# npm -v
5. Initialize the Next.js project development environment
Now, we’ll itialize the Next.js project development environment with the npx CLI build tool.
# npx create-next-app project-name
Note: Replace the project-name with you desired project name.
Change to the project directory list the directory contents.
# cd project-name
Start the development server.
# npm run dev
After the console reports:
ready – started server on http://localhost:3000
Navigate to your server IP on port 3000 in a web browser.
Verify the web page says Welcome to Next.js!.
To create an optimized production build of your project, close the development server with CTRL + C then run:
# npm run build && npm run start
After the command completes, a web server begins serving your web application. Navigate to your server IP on port 3000 and view the production build. This time it should load much faster.
That’s it. The installation is completed successfully.