A gun lock for receiving and clamping a cross-sectional portion of a firearm. A slide bar is provided for mounting the gun lock to a surface in a storage location. A locking assembly slidably mountable to the slide bar is provided. A set screw assembly for releasably locking the locking assembly onto the sliding bar is provided. A set screw and a set screw nut locks the locking assembly onto the slide bar. The set screw is accessible by a hex key through an opening in housing of the apparatus only when the ratchet arm is in the unlocked open position. A pivotably attachable ratchet arm which resembles typical handcuffs is provided that has a plurality of ratchet teeth that enables the gun lock to clamp a wide variety of cross-sectional portions of different weapons. A solenoid has a plunger adapted to engage one of the ratchet teeth of the ratchet arm to lock the rotatable ratchet arm in position around the cross-sectional portion of the weapon to be locked. The solenoid locking assembly is releasable via a switch and can be overridden with key.