     if fs.existsSync(directory)
       destinationPath = path.join(directory, commandName)
       unlinkCommand destinationPath, (error) =>
+        # Retry with privilige escalation.
+        if error?.code is 'EACCES' and unlinkCommandWithPrivilegeSync(destinationPath)
+          error = null
+
         if error?
           error = new Error "Could not remove file at #{destinationPath}." if error
           callback?(error)
         else
           symlinkCommand commandPath, destinationPath, (error) =>
+            # Retry with privilige escalation.
+            if error?.code is 'EACCES' and symlinkCommandWithPrivilegeSync(commandPath, destinationPath)
+              error = null
+
             error = new Error "Failed to symlink #{commandPath} to #{destinationPath}." if error
             callback?(error)
     else

        else
          fs.chmod(destinationPath, 0o755, callback)

unlinkCommand = (destinationPath, callback) ->
  fs.unlink destinationPath, (error) ->
    if error? and error.code isnt 'ENOENT'
      callback(error)
    else
      callback()

module.exports =
  getInstallDirectory: ->

async = require 'async'
fs = require 'fs-plus'
mkdirp = require 'mkdirp'
runas = require 'runas'

symlinkCommand = (sourcePath, destinationPath, callback) ->
  mkdirp path.dirname(destinationPath), (error) ->
