Getting started with the Netlify CLI

4 min read
On this page

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:

bash
npm install -g netlify-cli

Once installed, verify it works:

bash
netlify --version

If you see a version number, you’re good to go.

Logging in to Netlify#

To connect the CLI to your Netlify account, run:

bash
netlify login

This 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:

bash
netlify init

This 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:

bash
netlify deploy --prod

If you want to preview a deploy without publishing it, run:

bash
netlify deploy

This 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:

bash
netlify dev

This 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:

bash
netlify env:list

Add a new variable:

bash
netlify env:set API_KEY your_value_here

Remove a variable:

bash
netlify env:unset API_KEY

These changes apply immediately to future builds and deploys.

Working with Netlify Functions#

To test functions locally, run:

bash
netlify functions:serve

Functions become available at:

http://localhost:9999/.netlify/functions/function-name

This 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 account
  • netlify open: opens the site dashboard in your browser
  • netlify build: runs the build command locally
  • netlify 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.

Share:
Perttu Lähteenlahti

Written by

Perttu Lähteenlahti

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