Upgrading to hledger 2
hledger 2 reads hledger 1 data, and most hledger 1 users can switch to it with no changes. This page helps you check that and fix any problems that may arise. It covers the changes since hledger 1.52 that can affect existing setups; for the new features, see What's new in hledger 2, and for every change, the detailed release notes.
hledger 1 still works well, and both versions can be installed side by side.
Upgrade steps
Upgrading is essentially just: install a hledger 2 binary (or build it) and keep working.
But if you prefer, here's a more careful process:
-
Install hledger 2, keeping hledger 1 available under another name, eg by renaming its executable to
hledger1.Both versions read the same config file (if hledger 1 later refuses to run, see Config file errors).
-
Make sure your data files are backed up, or committed to version control.
-
Check your data with hledger 2:
$ hledger check(Add any extra checks you normally use, eg
hledger check -s.) -
If you import CSV files, run your usual import command with
--dry-runadded, which shows what would be imported without changing anything. Eg:$ hledger import --dry-run *.rules -
Compare your usual reports with hledger 1's. Eg:
$ diff <(hledger1 accounts) <(hledger accounts) $ diff <(hledger1 bs) <(hledger bs) $ diff <(hledger1 is) <(hledger is)(This works in bash or zsh. Elsewhere, save each report to a file and compare the files.)
-
Fix anything found, using the sections below. And update any scripts or config which use changed commands.
Errors you might see
You probably won't see these, but here are a few things that hledger 2 (or hledger 1) might complain about.
General errors
Config file errors
If you use hledger 2 config file features, such as multi-line command aliases,
hledger 1 will refuse to run, even for --version
(see Config files for the details).
Run it as hledger1 -n then, or give it its own config file with --conf.
And if hledger reports an unexpected config file error, check that an old hledger isn't running instead (eg one found earlier in your PATH).
Invalid decimal marks
When a decimal-mark directive (or CSV rule) is in effect,
a number that's clearly using the other decimal mark (eg 1,000.00 when decimal-mark , is declared),
or using the declared mark more than once (eg 1,2,34),
is now reported as an error. Fix the number, or the directive.
CSV rules lines beginning with *
In CSV rules files, comment lines may no longer begin with *; use # or ; instead.
"only one source rule is allowed"
hledger 1 used just one of a rules file's source rules (including any in its included files), ignoring the rest.
Now more than one is an error. Keep the one you want; if several data files share rules,
give each its own rules file, which includes the common rules.
"account name ... has an empty part"
Account names can no longer begin or end with :, or contain ::, like assets::bank; rename such accounts.
In CSV rules, this usually comes from an empty field in an account name, like account1 expenses:%category;
you could give it a default, eg account1 expenses:%{default(%category, "unknown")}.
(A trailing colon in apply account assets: is fine; it is ignored.)
"assert should be followed by none or some"
hledger 1 ignored Ledger-style assert EXPR directives.
hledger 2 has its own assert directive, so these are now an error.
Remove them, or rewrite them as hledger assert rules.
(This also replaces the hledger-check-fancyassertions script, which has been removed.)
"end apply year has no matching apply year"apply year is now scoped (see below), so a stray end apply year is an error. Remove it.
Failing balance assertions or checks
Some changes in file reading (see below)
could cause balance assertions or the accounts check to fail.
Lot errors
hledger 1 ignores basic cost basis annotations, like {$50}.
hledger 2 interprets and validates these, and may report the errors below.
If you don't want to deal with these now, you can run with --ignore-lots or -I.
For more help, see Start tracking lots.
"This acquire posting's cost basis ... differs from its transacted cost"
In a purchase like 10 AAPL {$50} @ $55, the two costs must agree.
If the difference is real (eg a gift with a carried-over cost basis),
record it in another posting, as in this gift example.
"no FOO lots available for disposal"
A sale (a negative amount with a {...} annotation) takes from a lot that the journal never acquires,
often because the journal starts partway through your investment history.
Add the missing purchases, or an opening entry which acquires the lots, giving each lot's original date and cost:
2026-01-01 opening lots
assets:stocks 10 AAPL {2024-03-15, $50}
equity:opening/closing balances
"This multi-commodity transaction is unbalanced"
This happens on a sale with a cost basis annotation and a gain posting, where @ is the original cost (hledger 1-style lot tracking).
hledger 2 expects @ to be the selling price;
see If you've been tracking investments in hledger 1.
"A final account name part enclosed in { } must be a valid lot subaccount name"
Account names ending in :{...} are reserved for lot subaccounts,
and are rejected unless the braces contain a valid lot name.
Rename such accounts.
Changes in file reading
These change how your journal, CSV rules or config files are interpreted. Comparing reports from both versions, as in the upgrade steps above, will show their effects, if any.
-
Inferred gains. If your journal has sales with cost basis annotations but no gain posting, like
-5 AAPL {$50} @ $70, hledger 2 infers the realised gain and posts it to a gain account (revenues:gainby default). This will appear on your income statement, which is usually what you want;-Igives hledger 1's results. -
Aliases and
apply account. Whenaliasdirectives andapply accountaffect the same entries, the aliases now apply first, to account names as written, and the parent account is added afterward (as in Ledger). hledger 1 did it the other way round. So aliases written with the parent account (alias business:checking = ...) no longer match, and aliases written without it (alias checking = ...) now do. This can make balance assertions or account checks fail. Update the aliases if you need to. (--aliasoptions are unaffected; they still apply last.) -
apply year.
apply yearis now scoped, as in Ledger: afterend apply year, dates without a year use the default year in effect before the block (from an earlierYdirective, or the current year), not the block's year. hledger 1 treatedapply yearlikeY, and ignoredend apply year. If you relied on that, changeapply yeartoY. -
Repeated commodity declarations. When a commodity is declared more than once, the later declaration now adds to the earlier one, and replaces its display style only if it gives one. With several
-ffiles, the last file's display style is now used (hledger 1 used the first's), and hledger warns if they differ. -
Repeated CSV settings. When a CSV setting like
date-formatorseparatoris written more than once, the last one now wins. If you wrote one before anincludeto override the included file's, move it after theinclude. -
CSV data directory. The
sourcerule now looks for bare file names and relative paths in adata/directory next to the main journal, then in~/Downloads. (Paths beginning with./or../are still relative to the rules file.) Thearchiverule now saves files indata/archive/there, instead of in adata/directory next to the rules file. -
Config file default command. A config file can no longer choose the command to run. A bare word at the top of its general section, which hledger 1 used as the default command, is now read as a query argument, which quietly filters every report. Remove it, and give the command on the command line.
Changes in commands and output
These affect how you run hledger and what it shows. If your scripts, aliases or config files depend on these, update them.
Renamed and removed
--tldris now--examples.stats -1is nowstats --oneline.--verbose-tagsis now an option ofprintandrewriteonly.hledger test(which runs the built-in unit tests) is nowhledger --test.- The
demoandcommandscommands have been removed. (hledger help commandslists the commands.) - The hledger-check-fancyassertions script has been removed; use assert directives instead.
Reports
-
register zero amounts.
registernow hides postings with a zero amount, likearegister;-Eshows them. -
print layout.
printnow aligns amounts by their decimal mark.--layout=hledger1gives the old layout. -
Decimal places. Amounts which hledger infers no longer affect a commodity's display precision, so some reports show fewer decimal places.
-
activity. This now shows a weekly chart counting transactions.
activity --postings -D -0shows daily posting counts, as hledger 1's did. -
accounts and payees. Query terms which only match transactions, like
date:ordesc:, now exclude declared accounts or payees which aren't used. Andpayees payee:REGEXnow matches declared payees. -
files.
filesnow also lists the CSV rules files and data files used, and reports a missing included file with a warning instead of failing. -
accounts --locations. Locations are now shown as FILE:LINE, without the column number.
-
commodities --used. This now shows only commodities used in transactions;
--pricedshows those used in P directives.
Queries
-
change: and balance: queries. These are new query prefixes, so a query for an account name beginning with
change:orbalance:now needsacct:before it. -
any: and all: queries. These now also work in posting reports like
registerandbalance, not just inprint.
hledger-ui and hledger-web
-
hledger-ui auto-reload. hledger-ui now watches your files and reloads automatically by default.
--no-watchturns this off. -
hledger-web remote access. When listening on a non-local address (set with
--host), hledger-web is now read-only by default. Add--allow=editto allow editing. -
hledger-web language. hledger-web now shows its pages in your browser's preferred language, if a translation is available (see Languages for the current list).
--lang enkeeps it in English. -
hledger-web defaults. hledger-web now opens on the balance sheet, with a report interval to suit the period, and shows depth 1 (top-level accounts) by default. The sidebar lists every account whatever the search, and hides its balances until you click its Balances heading or press
b; when shown, they are historical balances, not changes during the search's period. Thenkey now goes to the next page; useato open the add form.
Lot tracking
Once your data works with hledger 2, you can (if you want) start using its lot tracking feature. If you have been tracking investments in hledger 1, with or without lot subaccounts, those entries will still work in hledger 2; but converting them to hledger 2's lot tracking will greatly reduce manual toil and potential for mistakes. See Start tracking lots, which explains why and how, with advice for long investment histories and for converting hledger 1 entries.
Staying compatible with hledger 1
If you need to keep your files hledger-1-compatible,
eg because you use other apps not yet updated for hledger 2,
here is what to watch out for.
After edits, check your files with both versions, eg hledger check and hledger1 -n check.
Things hledger 1 rejects
hledger 1 reports an error for these:
skiplines under assert rules. hledger 1 ignores assert rules, but not theirskiplines. Instead of skipping, you can split a rule into periods around the skipped dates; this checks the same thing (balances in the later period still include earlier postings). Eg, instead of
writeassert none daily type:A balance:<0 skip 2026-03-04..2026-03-08
With many skips this gets unwieldy; then, keep the rule in a file read only by hledger 2 (see below).assert none daily to 2026-03-04 type:A balance:<0 assert none daily from 2026-03-08 type:A balance:<0- Amount expressions, like
$50.20 + $16.54. - Dated or labelled cost basis annotations, like
{2024-03-15, $50}or{"note", $50}(see below). - CSV or rules files included in a journal.
- New CSV rules, like
merge, in rules files that hledger 1 reads. - New config file features, like multi-line command aliases.
Run hledger 1 as
hledger1 -nto ignore the config file, or give it its own with--conf.
Things hledger 1 ignores
hledger 1 accepts these, but ignores them, so its reports can differ silently:
alias:tags on account declarations (account aliases). hledger 1 shows the aliased name as a separate account. Analiasdirective written just after the account declaration does the same thing, and works in both versions:account assets:checking alias chk = assets:checkingalias:tags on commodity declarations (commodity aliases). hledger 1 shows the aliased symbol as a separate commodity. There is no hledger 1 equivalent.- Assert rules. Only hledger 2 checks them.
- Lot tracking (see below).
Keeping hledger 2-only parts separate
When something has no compatible form, keep it where only hledger 2 will read it: in a top-level journal for hledger 2, which includes your main journal. Eg:
; hledger2.journal, read by hledger 2
include main.journal
commodity $ ; alias: USD
assert none daily type:A balance:<0
skip 2026-03-04..2026-03-08
Point LEDGER_FILE (or your config file) at hledger2.journal, and run hledger 1 on the main journal: hledger1 -n -f main.journal.
Lot entries
If you are using hledger 2's lot tracking, you should also:
- leave gains implicit, by omitting gain postings or their amounts (hledger 2 infers them, hledger 1 infers zero)
- and use Ledger-style cost basis annotations like
[2024-03-15] {$50}or(note) {$50}, which both versions can read (hledger 1 ignores them).
For more about how hledger 1 reads hledger 2's lot entries, see Keeping files readable by hledger 1.