Gibilterra it is such a special place that, for a visitor who is in those parts, one cannot certainly miss it, at least half day. Everything is on his side: mythology, historical events, geographic location, nature (including of course the famous Barbary apes), political situation (as a British enclave and an actual part of the United Kingdom).
If you are passing through and do not stop for the night, some precautions are needed to avoid unnecessarily wasting precious time, starting with parking considerations. THE parking spaces in Gibraltar they are few and difficult to find. There are some of a decent size just past border, but quite expensive. If you have no problem taking a stroll, the best solution is to park in the last Spanish city, The line, just before the border: in this way you save on parking (and on Saturdays and Sundays you don't pay) and you avoid long queues at the exit customs control. To get to the center it takes about twenty minutes on foot or one ten by bus, with the further particularity of having to cross the airport runway transversely.
In the center you can take the pedestrian street Main Street, which between shops and chapels (do not miss the royal chapel, free and very pleasant) leads to the departure station of the cable car that leads to the fortress. Here you have 3 choices to get to where the live famous monkeys: on foot, quite demanding, at least 3-4 hours to do the whole tour; with the Cabinovia, certainly not cheap but fast, around € 14 each; with a guided tour by minibus, about 30 €, less in direct contact with nature (and the monkeys) but complete with a visit to all the different historical-naturalistic-archaeological sites of the fortress. In any case, the climb is worth the price or the effort, if only for the extraordinary peculiarity of the place.
Technical information: if you refer to English and Spanish customs, including timetables, keep the latter as a reference! Don't hope to find activities open at 9 am ...