---
title: Anchor CLI Basics
seoTitle: Introductory commands for getting started on the Anchor CLI
description:
  This section walks through some common Anchor CLI commands to get you started.
---

This section provides some common commands and examples to help you get started
using the [Anchor CLI](https://www.anchor-lang.com/docs).

<Steps>
<Step>

### Initialize the project

Create a new Anchor project by running the command shown below. It will create a
new directory with the project name and use it to initialize a new Anchor
project.

```terminal
$ anchor init <project-name>
```

For example, the command below will create a project called `my-project`. The
`my-project` directory will contain a basic Rust program and TypeScript test
template.

```terminal
$ anchor init my-project
```

Then navigate to the project directory:

```terminal
$ cd <project-name>
```

See Anchor's
[project file structure](https://www.anchor-lang.com/docs/quickstart/local#project-file-structure).

</Step>
<Step>

### Build the program

To build your project, run the following command:

```terminal
$ anchor build
```

You can find the compiled program in the `/target/deploy` directory.

<Callout type="warn">

When running `anchor build`, if you encounter the following errors:

<Accordions>
<Accordion title="error: not a directory">

```
error: not a directory: '.../solana-release/bin/sdk/sbf/dependencies/platform-tools/rust/lib'
```

Try these solutions:

1. Force install using the following command:

```terminal
$ cargo build-sbf --force-tools-install
```

2. If the preceding solution doesn't work, clear the Solana cache:

```terminal
$ rm -rf ~/.cache/solana/*
```

</Accordion>

<Accordion title="lock file version 4 requires `-Znext-lockfile-bump">
You can fix this by changing the version field of `Cargo.lock` file from 4 to 3:

```diff title="Cargo.lock"
-version = 4
+version = 3
```

See [this issue](https://github.com/solana-foundation/anchor/issues/3392) for
more information.

</Accordion>

</Accordions>

After applying the preceding solution, attempt to run _shell`anchor build`_
again.

</Callout>

</Step>
<Step>

### Deploy the program

To deploy your project, run the following command:

```terminal
$ anchor deploy
```

This command deploys your program to the `cluster` specified in the
[`Anchor.toml`](https://www.anchor-lang.com/docs/references/anchor-toml) file.

</Step>
<Step>

### Test the program

To test your project, run the following command:

```terminal
$ anchor test
```

This command builds, deploys, and runs the tests for your project.

<Callout>
  When using the `localnet` cluster, Anchor automatically starts a local
  validator, deploys the program, runs tests, then stops the validator.
</Callout>

<Callout type="warn">

Either of the following errors may indicate that you don't have Node.js or Yarn
installed:

```
Permission denied (os error 13)
```

```
No such file or directory (os error 2)
```

</Callout>

</Step>
</Steps>
