In this article, we’ll explain you how it is easy to install Next.js on Ubuntu 20.04.
Next.js is an open-source Javascript framework. It is built on React.js, which allows developers to create server-side rendered and statically generated React applications.
Prerequisites
- 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 –
Install NodeJS.
# 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.
http://192.168.1.10:3000/
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.