Skip to content
Latchkey

ln: Usage, Options & Common CI Errors

ln creates links - symbolic (-s) pointers or hard links to the same inode.

ln wires up symlinks for toolchain shims and "current" release pointers. The two recurring CI errors are "File exists" (no -f) and links that dangle because the target path was relative.

What it does

ln creates a new link to a file. Without -s it makes a hard link (another name for the same inode); with -s it makes a symbolic link (a path pointer that can cross filesystems and point at directories).

Common usage

Terminal
ln -s /opt/app/releases/v2 /opt/app/current
ln -sf node-18 node              # force-replace existing link
ln -s ../shared ./shared         # relative target
ln -snf /new/target link         # safely retarget a dir symlink
ln file.txt hardlink.txt         # hard link

Options

FlagWhat it does
-s / --symbolicMake a symbolic link (not hard)
-f / --forceRemove an existing destination first
-n / --no-dereferenceTreat an existing-link dest as a file
-r / --relativeMake a symlink target relative (GNU)
-TAlways treat dest as a normal file

Common errors in CI

ln: failed to create symbolic link "X": File exists - the destination already exists; add -f (and -n when it is a symlink to a directory, else you create a link inside the target). A symlink with a relative target resolves relative to the link's location, so it dangles if you move the link - use an absolute target or ln -r. Hard links cannot cross filesystems or link directories.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →