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.
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.
curl --proto '=https' --tlsv1.2 -sSfL https://solana install.solana.workers.dev | bash
source ~/.profile or whatever it spits out.solana --version && rustc --version && anchor --versionExpect 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.
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:
| OS | Command | Version Check |
|---|---|---|
| Mac/Linux | curl .. | bash | solana --version |
| Windows WSL | Same curl | Same |
| Alt: Homebrew | brew install solana | May lag releases |
~/.config/solana/id.json. That's your wallet.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.
solana config set --url devnetsolana config set --url testnetsolana config set --url localhostsolana config set --url https://your rpc.comWhy devnet first? Free SOL faucets. Mainnet costs real money-fees around 0.000005 SOL per tx. Tiny, but adds up.
First time? No keypair yet. CLI nags you.
solana keygen new. Enter passphrase. Boom, id.json created. Pubkey prints out.solana keygen pubkey ~/.config/solana/id.json or just solana address.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.
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.
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.
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.
Three main ones. Here's a quick compare:
| Cluster | RPC URL | SOL Real? | Use Case |
|---|---|---|---|
| Mainnet beta | https://api.mainnet beta.solana.com | Yes | Production |
| Devnet | https://api.devnet.solana.com | Fake (faucet) | Testing dApps |
| Testnet | https://api.testnet.solana.com | Fake | Validator tests |
| Localhost | http://localhost:8899 | Fake | Local 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.
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.
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.
For big txs. Create: solana address lookup table create. Extend later. Cuts tx size, saves fees.
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.
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.