Nextjs Installation
Nextjs Installation
System Requirements:
Automatic Installation
We recommend starting a new Next.js app using create-next-app , which sets up
everything automatically for you. To create a project, run:
Terminal
npx create-next-app@latest
Terminal
What is your project named? my-appWould you like to use TypeScript? No / YesWould
you like to use ESLint? No / YesWould you like to use Tailwind CSS? No / YesWould you
like to use `src/` directory? No / YesWould you like to use App Router? (recommended)
No / YesWould you like to customize the default import alias (@/*)? No / YesWhat import
alias would you like configured? @/*
After the prompts, create-next-app will create a folder with your project name and
install the required dependencies.
If you're new to Next.js, see the project structure docs for an overview of all the
possible files and folders in your application.
Good to know:
Next.js now ships with TypeScript, ESLint, and Tailwind CSS configuration by
default.
You can optionally use a src directory in the root of your project to separate
your application's code from configuration files.
Manual Installation
To manually create a new Next.js app, install the required packages:
Terminal
npm install next@latest react@latest react-dom@latest
Creating directories
Next.js uses file-system routing, which means the routes in your application are
determined by how you structure your files.
Create an app/ folder, then add a layout.tsx and page.tsx file. These will be
rendered when the user visits the root of your application ( / ).
Good to know: If you forget to create layout.tsx , Next.js will automatically create
this file when running the development server with next dev .
Next, add an _app.tsx file inside pages/ to define the global layout. Learn more
about the custom App file.
pages/_app.tsx
TypeScript
import type { AppProps } from 'next/app' export default function App({ Component,
pageProps }: AppProps) { return <Component {...pageProps} />}
Finally, add a _document.tsx file inside pages/ to control the initial response from
the server. Learn more about the custom Document file.
pages/_document.tsx
TypeScript
import { Html, Head, Main, NextScript } from 'next/document' export default function
Document() { return ( <Html> <Head /> <body> <Main />
<NextScript /> </body> </Html> )}
Good to know: Although you can use both routers in the same project, routes
in app will be prioritized over pages . We recommend using only one router in your
new project to avoid confusion.