How to change a symlink in OS X?

Solution 1:

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.

Solution 2:

ln -hfs newlocation existinglink

or

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

Solution 3:

Try:

unlink /path/to/current/link
ln -s /path/to/target /path/to/symbolic/link