Master Solana CLI: Setup, Config, and Commands.

Okay, picture this. You're testing a new program on devnet, everything's smooth. Then you accidentally deploy to mainnet. Boom. Gone. 2 SOL in fees. Hurt, right? That's why mastering Solana CLI starts with setup you won't screw up. I usually tell friends: get this right first, or you'll hate life later.

Why does this happen? CLI points to mainnet by default. But most of us dev on devnet or localhost. Sound familiar? Let's fix that. We'll install, config, and hit commands. No fluff. Just steps that work.

And honestly, once you're set, it's game changing. Airdrop free SOL, check balances, deploy programs-all from terminal. Pretty much everything you need without a GUI.

Installing Solana CLI without the headache

Look, there's a one command wonder for Mac, Linux, even Windows WSL. I use it every time I spin up a new machine. Grabs Rust, Solana CLI, Anchor, Node, Yarn. Done.

  1. Paste this in your terminal:
  2. curl --proto '=https' --tlsv1.2 -sSfL https://solana install.solana.workers.dev | bash
  3. Restart terminal. Or source your profile: source ~/.profile or whatever it spits out.
  4. Check versions: solana --version && rustc --version && anchor --version

Expect something like Solana CLI 1.18.x. If it bombs? Permissions issue probably. Run sudo chown -R $USER ~/.config/solana. Fixed it for me twice.

Windows? Don't sweat it

WSL is your friend. Install Ubuntu from Microsoft Store, open it, then run that curl command above. Native Windows? Messier. Download the installer from releases, but honestly, WSL's faster. I usually skip native unless forced.

Quick table for versions I run on my setups:

OSCommandVersion Check
Mac/Linuxcurl .. | bashsolana --version
Windows WSLSame curlSame
Alt: Homebrewbrew install solanaMay lag releases

Config: Where all the magic hides

  • Defaults to mainnet beta. Don't touch real SOL yet.
  • Keypair at ~/.config/solana/id.json. That's your wallet.
  • Run solana config get. Shows RPC URL, websocket, keypair path, commitment.

Output looks like:

Config File: /Users/you/.config/solana/cli/config.yml
RPC URL: https://api.mainnet beta.solana.com
WebSocket URL: wss://api.mainnet beta.solana.com/ (computed)
Keypair Path: /Users/you/.config/solana/id.json
Commitment: confirmed

The thing is, commitment? Processed (fastest, riskiest), confirmed, finalized (safest). I stick to confirmed for most stuff.

Switch clusters? Easy.

  • Devnet: solana config set --url devnet
  • Testnet: solana config set --url testnet
  • Localhost (for validators): solana config set --url localhost
  • Custom RPC: solana config set --url https://your rpc.com

Why devnet first? Free SOL faucets. Mainnet costs real money-fees around 0.000005 SOL per tx. Tiny, but adds up.

Wallets: Generate, recover, don't lose 'em

First time? No keypair yet. CLI nags you.

  1. Grind a new one: solana keygen new. Enter passphrase. Boom, id.json created. Pubkey prints out.
  2. Pubkey only? solana keygen pubkey ~/.config/solana/id.json or just solana address.
  3. Recover old? solana keygen recover. Prompt for seed phrase.

In my experience, back up that seed phrase. Like, tattoo it if you have to. Lost mine once. 5 SOL gone. Never again.

Multiple wallets? Use -k path/to/other.json flag on commands. Or solana config set --keypair mywallet.json.

Essential commands you'll use daily

Okay, now the fun part. These are the ones I copy paste constantly. Short ones first.

Balance check. solana balance. Shows SOL with lamports (1 SOL = 1e9 lamports). Try solana balance --lamports for raw numbers.

Airdrop. Devnet/testnet only. solana airdrop 2 for 2 SOL. Limits? 24 SOL/day usually. If faucet's dry: solana airdrop 1 --url devnet. What's next if it fails? Wait 2 mins, retry. Or hit multiple faucets.

Account info. solana account <PUBKEY>. Dumps raw data. For programs, add --output json.

Transferring SOL like a pro

Send to a friend? solana transfer RECIPIENT_ADDRESS 0.5 --allow unfunded recipient. That flag funds new accounts. Fee? ~0.000005 SOL.

Common gotcha: Insufficient funds. Check balance first. And use --dry run to simulate: solana transfer DEST 1 --dry run. Saves mistakes.

Program deployment basics

You've got Anchor project? Build with anchor build. Deploy: anchor deploy. But CLI handles it under the hood.

Manual way: solana program deploy target/deploy/yourprogram.so. Needs ~0.1-2 SOL rent depending on size. Devnet, airdrop more.

Verify: solana program show <PROGRAMID>. Lists executable data, upgrade authority.

Issues? "Program not found." Means bad ID. "Insufficient funds." Airdrop. "Invalid account data." Rebuild.

Clusters deep dive

Three main ones. Here's a quick compare:

ClusterRPC URLSOL Real?Use Case
Mainnet betahttps://api.mainnet beta.solana.comYesProduction
Devnethttps://api.devnet.solana.comFake (faucet)Testing dApps
Testnethttps://api.testnet.solana.comFakeValidator tests
Localhosthttp://localhost:8899FakeLocal dev

Switch with solana config set --url devnet. I usually alias it: add alias sdev="solana config set --url devnet" to .bashrc. Saves seconds.

Custom RPC? Paid ones like Helius or Quicknode. Faster, reliable. Free tiers cap requests.

Troubleshooting the crap that breaks

CLI freezes? solana config set --url https://api.devnet.solana.com-sometimes RPC hiccups.

"No such command." Update: solana install update.

Keypair permission denied? chmod 600 ~/.config/solana/id.json.

Airdrop fails with "Unable to confirm transaction." Network busy. Retry or switch commitment: solana config set --commitment processed. Riskier, but faster.

Local validator? solana test validator. Kills port 8899 if running. Use pkill -f solana test validator.

Stake, validators, advanced stuff

Got real SOL? Delegate stake: First create account solana stakes 10 <VOTER_PUBKEY>. No, wait: spl stake stake account create if using SPL.

CLI has solana stake account subcommands. Check solana stake account --help.

Leader schedule: solana leaders --epoch EPOCH. See who's producing blocks.

Gossip? solana gossip. Dumps cluster peers. Nerdy, but useful for node ops.

Address lookup tables (new hotness)

For big txs. Create: solana address lookup table create. Extend later. Cuts tx size, saves fees.

Integrating with scripts

Node.js? Use @solana/web3.js. Load keypair from CLI path.

const fs = require('fs');
const { Keypair } = require('@solana/web3.js');
const keypair = Keypair.fromSecretKey( Uint8Array.from(JSON.parse(fs.readFileSync('/path/to/id.json')))
);

Python? solana py. Same idea.

I usually script airdrops in loops for testing. But rate limit yourself-faucets ban abusers.

Update and maintain

Weekly: solana install update. Or agave install update if on Anza branch. Versions matter-bugs get fixed.

Config file at ~/.config/solana/cli/config.yml. Edit manually for websocket overrides.

Last tip: solana --help. Goldmine. Subcommands galore. account, program, validators, rent.. explore.