Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Pathname#make_symlink

(::String | ::Pathname | ::_ToStr old) -> ::Integer
make_symlink(target_path) → 0

Not supported on some platforms.

Creates a symbolic link at the path in self to the entry at target_path:

Example
file_pn = Pathname('/etc/passwd')
link_pn = Pathname('/tmp/foo')
link_pn.make_symlink(file_pn)
link_pn.readlink             # => #<Pathname:/etc/passwd>
file_pn.read == link_pn.read # => true

If the entry at target_path is itself a symbolic link, that link is not followed:

Example
link2_pn = Pathname('/tmp/bar')
link2_pn.make_symlink(link_pn)
link2_pn.readlink             # => #<Pathname:/tmp/foo>
link2_pn.read == file_pn.read # => true
# Clean up.
link_pn.delete
link2_pn.delete
See also #make_link #mkdir #lutime #mkpath also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0