> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Anchor CLI Basics

> 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 titleSize="h2">
<Step title="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.

```bash Terminal
anchor init <project-name>
```

For example, the command below will create a project called `my-project`. The
`my-project` directory will contain a modular Rust program and a Rust test
template that uses LiteSVM.

```bash Terminal
anchor init my-project
```

To generate a TypeScript test template instead, choose one explicitly. For
example, use the Mocha template:

```bash Terminal
anchor init my-project --test-template mocha
```

TypeScript test templates require Node.js and a JavaScript package manager.

Then navigate to the project directory:

```bash Terminal
cd <project-name>
```

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

</Step>
<Step title="Build the program">

To build your project, run the following command:

```bash Terminal
anchor build
```

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

<Warning>
  **Platform tools failed to install**

  If the build reports an invalid platform-tools directory, reinstall the SBF
  build tools, then retry the build:

  ```bash Terminal
  cargo build-sbf --force-tools-install
  anchor build
  ```

</Warning>

</Step>
<Step title="Deploy the program">

To deploy your project, run the following command:

```bash Terminal
anchor program deploy
```

This command deploys the program that `anchor build` wrote to `target/deploy`
to the `cluster` specified in the
[`Anchor.toml`](https://www.anchor-lang.com/docs/references/anchor-toml) file.
To target a different cluster, add `--provider.cluster`, for example
`anchor program deploy --provider.cluster devnet`. If your workspace contains
more than one program, select one with `--program-name <name>`.

`anchor program deploy` replaces `anchor deploy`, which still works but prints
a deprecation warning.

</Step>
<Step title="Test the program">

To test your project, run the following command:

```bash Terminal
anchor test
```

This command builds your program and runs the test script defined in
`Anchor.toml`.

<Note>
  For the default LiteSVM template, the test script is `cargo test` and no
  validator is started. For the Mocha or Jest templates on the `localnet`
  cluster, Anchor starts a local validator, deploys the program, runs the tests,
  then stops the validator.
</Note>

<Warning>
Anchor CLI 1.2 builds SBPF v3 programs by default (it passes `--arch v3` to
`cargo build-sbf`), but the template that `anchor init` creates in Anchor 1.2.0
and 1.2.1 pins LiteSVM 0.10, which can't load v3 programs. With those versions,
`anchor test` on the default template fails with
`Err(Instruction(InvalidAccountData))` in `tests/test_initialize.rs`. Build for
the v0 architecture, then test without rebuilding:

```bash Terminal
anchor build --arch v0
anchor test --skip-build
```

Anchor 1.2.2 and later pin LiteSVM 0.15, which loads v3 programs, so
`anchor test` works on the default template.

Anchor 1.1.2 installed with AVM (as the installer does) runs with Solana CLI
3.1.10, which AVM installs and activates the first time `anchor` runs, so it
builds v0 programs and isn't affected. Without AVM, on Solana CLI 4.3 or later,
`anchor build` fails with `Platform tools v1.52 is incompatible with SBPFv3`;
see the workaround in
[Build your first program](/developers/docs/programs/build-first-program#run-test).
The `--arch` flag of `anchor build` exists only in Anchor CLI 1.2 and later;
with Anchor 1.1, pass it to `cargo build-sbf` after `--`.
</Warning>

<Warning>

**JavaScript test runner errors**

If you selected a JavaScript or TypeScript test template, either of the
following errors may indicate that Node.js or the configured package manager is
not installed:

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

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

</Warning>

</Step>
</Steps>
