Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I change where a symlink points to, without deleting and creating a new one (with ln -s "/path/to/point/to" "/path/where/symlink/is")?

When I tried doing that to Java's "Current" symlink, Java wouldn't even work (from the command line, at least, said 'Segmentation Fault') but it was back to normal when I restored the old "Current" symlink with Time Machine (but later I found out I should use /Applications/Utilities/Java anyway to change current java version).

share|improve this question
up vote 5 down vote accepted
mkdir /path/where/newsymlink
ln -s /path/to/point/to /path/where/newsymlink/is
mv /path/where/newsymlink/is /path/where/symlink/
rmdir /path/where/newsymlink

However, the Java Preferences utility changes more than just a symbolic link; you should use that to ensure that the Java version is changed.

share|improve this answer
wouldn't the mv command just rename it..? – Mk12 Sep 6 '09 at 19:17
.. I tried that, it justs moves the new symlink into the folder that the old one points to. – Mk12 Sep 6 '09 at 19:26
The first command makes the symlink that points where you want, and the second command replaces the existing pointer to the old place with the pointer to the new place. The mv is atomic so the symlink will always exist. – mark4o Sep 7 '09 at 0:00
.. But it still doesn't work.. it moves the new pointer into the folder that the old one points to. – Mk12 Sep 7 '09 at 2:08
/path/where/symlink/is is the symlink that you are changing. Using these commands will change it to point to /path/to/point/to. The folder that the original symlink points to is not touched at all. – mark4o Sep 7 '09 at 7:20


unlink /path/to/current/link
ln -s /path/to/target /path/to/symbolic/link
share|improve this answer
On my late 2013 MacBook Pro with Mavericks, I had to switch the two parameters: ln -s /path/to/symbolic/link /path/to/target – Moonwalkr Feb 11 '14 at 14:35
+1 Tried this as described and work flawlessly – OscarRyz Aug 29 '14 at 19:11
ln -hfs newlocation existinglink


ln -nfs newlocation existinglink

will change the existing link to point to newlocation

(the -n and -h are identical in operation)

From 'man ln'

-h If the target_file or target_dir is a symbolic link, do not follow it. This is most useful with the -f option, to replace a symlink which may point to a directory.

-f If the target file already exists, then unlink it so that the link may occur. (The -f option overrides any previous -i options.)

-s Creae a symbolic link

share|improve this answer

The ln command doesn't let you change links, only create new ones.

share|improve this answer

Have you compared the permissions on the links and on the targets before and after you change the link? You might just need to follow up with the appropriate chown and chmod commands to get it working.

share|improve this answer
Well I don't even know how to change it so no. And I don't know what chown and chmod do. – Mk12 Sep 6 '09 at 13:22
chown changes ownership of a file and/or directory. chmod changes permissions of a file and/or directory. These are standard in just about every unix platform. Too much detail to explain each here, so I would recommend googling each for tutorials. You can also do "man chown" or "man chmod" to read the actual manual of the command (hit q to get out of the manual). – churnd Sep 6 '09 at 13:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .