Getting started with the Netlify CLI
On this page
- Introduction
- What is the Netlify CLI?
- Prerequisites
- Installing the Netlify CLI
- Logging in to Netlify
- Linking a local project to a Netlify site
- Deploying from the command line
- Running Netlify locally
- Managing environment variables
- Working with Netlify Functions
- Common CLI commands to remember
- When to use the CLI vs the dashboard
- Where to start
Introduction#
If you use Netlify regularly, the Netlify CLI can quickly become one of your favorite tools. It lets you interact with Netlify directly from your terminal, which means fewer dashboard clicks and faster feedback while developing.
With the CLI, you can deploy sites, run Netlify features locally, manage environment variables, trigger builds, and even scaffold new projects.
What is the Netlify CLI?#
The Netlify CLI is a command-line tool that connects your local machine to your Netlify account. It works on macOS, Windows, and Linux, and integrates nicely with most modern frameworks.
Some common things people use the CLI for:
- Deploying sites without opening the dashboard
- Running a local development server that mirrors Netlify’s production behavior
- Testing Netlify Functions locally
- Managing environment variables
- Automating workflows in CI or scripts
Prerequisites#
Before getting started, make sure you have:
- Node.js installed (version 18 or newer is recommended)
- A Netlify account
- A project folder with a site you want to deploy
Installing the Netlify CLI#
The recommended way to install the CLI is using npm:
npm install -g netlify-cliOnce installed, verify it works:
netlify --versionIf you see a version number, you’re good to go.
Logging in to Netlify#
To connect the CLI to your Netlify account, run:
netlify loginThis opens a browser window where you can authorize the CLI. After approving access, your terminal session will be authenticated.
You only need to do this once per machine.
Linking a local project to a Netlify site#
Navigate to your project directory and run:
netlify initThis command guides you through:
- Creating a new Netlify site or linking an existing one
- Choosing a team
- Selecting a build command and publish directory (if applicable)
After this step, Netlify creates a .netlify folder in your project that stores site metadata.
Deploying from the command line#
To deploy a production build, run:
netlify deploy --prodIf you want to preview a deploy without publishing it, run:
netlify deployThis creates a draft deploy and returns a unique preview URL, which is great for quick checks or sharing work-in-progress changes.
Running Netlify locally#
One of the most useful CLI features is the local dev server:
netlify devThis command:
- Runs your framework’s dev server
- Injects Netlify environment variables
- Proxies Netlify Functions and redirects
- Mimics Netlify’s routing behavior
It’s especially helpful when working with forms, functions, or redirects that don’t behave the same on a plain local server.
Managing environment variables#
You can list environment variables for a site with:
netlify env:listAdd a new variable:
netlify env:set API_KEY your_value_hereRemove a variable:
netlify env:unset API_KEYThese changes apply immediately to future builds and deploys.
Working with Netlify Functions#
To test functions locally, run:
netlify functions:serveFunctions become available at:
http://localhost:9999/.netlify/functions/function-nameThis allows you to test serverless logic without deploying every change.
Common CLI commands to remember#
Here are a few commands you’ll likely use often:
netlify status: shows the linked site and accountnetlify open: opens the site dashboard in your browsernetlify build: runs the build command locallynetlify logs:function: views function logs
When to use the CLI vs the dashboard#
The dashboard is great for configuration and visual feedback, but the CLI shines when:
- You want fast deploys without context switching
- You’re working locally with functions or redirects
- You’re automating tasks in scripts or CI pipelines
You'll probably end up using both together.
Where to start#
Even starting with just netlify init, netlify deploy, and netlify dev can significantly speed up your workflow.

Written by
Developer Advocate at RevenueCat and creator of Netli.fyi. Building on Netlify since 2019 and writing from hands-on experience deploying dozens of production sites.
More about the author