Getting started with the Netlify CLI

Getting started with the Netlify CLI

Perttu Lähteenlahti
4 min read
clideploymentdeveloper-toolsworkflow
Share:

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. This guide walks through the essentials so you can start using the Netlify CLI with confidence.

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-cli

Once installed, verify it works:

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:

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:

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:

netlify deploy --prod

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

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:

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:

netlify env:list

Add a new variable:

netlify env:set API_KEY your_value_here

Remove a variable:

netlify env:unset API_KEY

These changes apply immediately to future builds and deploys.

Working with Netlify Functions

To test functions locally, run:

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

Most experienced Netlify users end up using both together.

Final thoughts

The Netlify CLI gives you superpowers once you get comfortable with it. Even starting with just netlify init, netlify deploy, and netlify dev can significantly speed up your workflow.

As your projects grow, the CLI becomes an essential part of working efficiently with Netlify.

Manage Netlify on the go

Download Netli.fyi and monitor your sites, check deploys, and manage your projects from anywhere.

Related articles