{"id":3051,"date":"2025-06-23T06:05:59","date_gmt":"2025-07-07T13:59:14","guid":{"rendered":""},"modified":"2025-02-02T00:46:19","modified_gmt":"2025-02-01T23:46:19","slug":"how-to-install-next-js-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/how-to-install-next-js-on-ubuntu-22-04\/","title":{"rendered":"Linux VPS &#038; VPS Windows Setup Guide | NetCloud24 Next.js on Ubuntu 22.04"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<header>\n<h1>\u00a0<\/h1>\n<\/header>\n<article>\n<p><strong>Next.js<\/strong> is a popular open-source React framework used to build server-side rendering and static web applications. It offers a fast, efficient, and scalable solution for modern web development. In this guide, we will show you how to install Next.js on <strong>Ubuntu 22.04<\/strong>. Hosting your Next.js application on a  ensures better performance, control, and scalability, making it an ideal choice for high-traffic applications running on a <strong>VPS server<\/strong>.<\/p>\n<h2>Step 1: Update Your VPS Server<\/h2>\n<p>Before installing Next.js, make sure your <a href=\"https:\/\/ie.netcloud24.com\">VPS server<\/a> is up to date. Run the following commands to update your system:<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<p>Running Next.js on a <strong>Windows VPS<\/strong> ensures that your application benefits from dedicated resources, offering improved performance and scalability as your traffic grows.<\/p>\n<h2>Step 2: Install Node.js<\/h2>\n<p>Next.js is built using Node.js, so you\u2019ll need to install Node.js before setting up Next.js. Install Node.js using the following commands:<\/p>\n<pre><code>\r\ncurl -fsSL https:\/\/deb.nodesource.com\/setup_18.x | sudo -E bash -\r\nsudo apt install -y nodejs\r\n<\/code><\/pre>\n<p>Once installed, verify the Node.js installation by checking the version:<\/p>\n<pre><code>node -v<\/code><\/pre>\n<p>You should see Node.js 18.x or a later version installed.<\/p>\n<h2>Step 3: Install Next.js<\/h2>\n<p>With Node.js installed, you can now set up your Next.js application. First, create a new directory for your project:<\/p>\n<pre><code>mkdir ~\/nextjs-app &amp;&amp; cd ~\/nextjs-app<\/code><\/pre>\n<p>Use the <strong>Create Next App<\/strong> command to set up a new Next.js project:<\/p>\n<pre><code>npx create-next-app@latest .<\/code><\/pre>\n<p>This command will generate the basic Next.js structure in the current directory. Follow the prompts to configure your new application.<\/p>\n<h2>Step 4: Start the Next.js Development Server<\/h2>\n<p>After setting up your project, you can start the Next.js development server using the following command:<\/p>\n<pre><code>npm run dev<\/code><\/pre>\n<p>Next.js will start the development server on <code>http:\/\/localhost:3000<\/code>. You can access your application by navigating to <code>http:\/\/your-server-ip:3000<\/code> in your browser.<\/p>\n<h2>Step 5: Configure Next.js for Production<\/h2>\n<p>When deploying Next.js in a production environment, you need to build the project and start it in production mode. Run the following commands to build and start the project:<\/p>\n<pre><code>\r\nnpm run build\r\nnpm start\r\n<\/code><\/pre>\n<p>The <code>npm run build<\/code> command optimizes your Next.js application for production by compiling all files, and <code>npm start<\/code> launches the application in production mode.<\/p>\n<h2>Step 6: Set Up a Process Manager (Optional)<\/h2>\n<p>To ensure that your Next.js application runs continuously and restarts automatically in case of a crash, you can use a process manager like <strong>PM2<\/strong>. Install PM2 globally by running:<\/p>\n<pre><code>sudo npm install pm2 -g<\/code><\/pre>\n<p>Next, start your application using PM2:<\/p>\n<pre><code>pm2 start npm --name \"nextjs-app\" -- run start<\/code><\/pre>\n<p>PM2 will keep your Next.js application running in the background, and you can manage it using the following commands:<\/p>\n<ul>\n<ul>\n<li>Check the status of your application:<\/li>\n<\/ul>\n<\/ul>\n<pre><code>pm2 status<\/code><\/pre>\n<ul>\n<ul>\n<li>Restart your application:<\/li>\n<\/ul>\n<\/ul>\n<pre><code>pm2 restart nextjs-app<\/code><\/pre>\n<ul>\n<ul>\n<li>Stop your application:<\/li>\n<\/ul>\n<\/ul>\n<pre><code>pm2 stop nextjs-app<\/code><\/pre>\n<h2>Step 7: Configure Nginx as a Reverse Proxy (Optional)<\/h2>\n<p>For a production-ready deployment, it is common to configure <strong>Nginx<\/strong> as a reverse proxy to handle HTTP traffic and forward requests to your Next.js application running on port 3000. Install Nginx using the following command:<\/p>\n<pre><code>sudo apt install nginx -y<\/code><\/pre>\n<p>Once installed, create a new Nginx configuration file for your application:<\/p>\n<pre><code>sudo nano \/etc\/nginx\/sites-available\/nextjs<\/code><\/pre>\n<p>Add the following configuration, replacing <code>your-domain.com<\/code> with your actual domain or server IP address:<\/p>\n<pre><code>\r\nserver {\r\n    listen 80;\r\n    server_name your-domain.com;\r\n\r\n    location \/ {\r\n        proxy_pass http:\/\/localhost:3000;\r\n        proxy_set_header Host $host;\r\n        proxy_set_header X-Real-IP $remote_addr;\r\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n        proxy_set_header X-Forwarded-Proto $scheme;\r\n    }\r\n\r\n    error_log \/var\/log\/nginx\/nextjs-error.log;\r\n    access_log \/var\/log\/nginx\/nextjs-access.log;\r\n}\r\n<\/code><\/pre>\n<p>Save the file and exit the editor. Enable the configuration by creating a symbolic link to <code>sites-enabled<\/code>:<\/p>\n<pre><code>sudo ln -s \/etc\/nginx\/sites-available\/nextjs \/etc\/nginx\/sites-enabled\/<\/code><\/pre>\n<p>Test the Nginx configuration:<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<p>If the test is successful, restart Nginx:<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2>Step 8: Optimize Your VPS Server for Next.js<\/h2>\n<p>To ensure that your Next.js application runs smoothly and can handle high traffic, hosting it on a  is highly recommended. A <strong>VPS server<\/strong> provides dedicated resources such as CPU, memory, and storage, allowing your application to scale efficiently and maintain optimal performance even under heavy traffic.<\/p>\n<h2>Conclusion<\/h2>\n<p>Next.js is a powerful framework for building modern web applications, and setting it up on Ubuntu 22.04 is a straightforward process. By hosting your application on a , you gain better control, scalability, and performance, ensuring that your Next.js application can grow and handle increasing user demands seamlessly.<\/p>\n<p>For more information about VPS hosting and optimizing your Next.js deployment, visit  today.<\/p>\n<\/article>\n<footer>\n<p>\u00a9 2024 Windows VPS &#8211; All Rights Reserved<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 Next.js is a popular open-source React framework used to build server-side rendering and static web applications. It offers a fast, efficient, and scalable solution for modern\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-3051","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=3051"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/3051\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=3051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=3051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=3051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}