THE hump of Arthur’s Seat looms over the Edinburgh skyline, the streets below filled with the familiar haunts of one of crime fiction’s most beloved characters. It is 30 years since author Ian Rankin introduced the world to John Rebus, his flawed but brilliant detective.

He’s had quite a journey, reflects Rankin, whose work will take centre stage at the inaugural RebusFest this month, a three-day celebration of talks, music, walking tours and screenings to mark the 30th anniversary of the first novel in 1987.

Fife-born Rankin has charted the adventures of Rebus in 21 books, selling more than 30 million copies in 36 languages. His literary creation has been a hit television series (although famously Rankin has never watched it) and adapted by BBC Radio Four.

These days it is rare to walk into a bookshop and not see Rankin’s novels stacked high among the bestsellers. They are a ubiquitous sight on planes, trains and sun loungers.

Rankin, 57, first breathed life into Rebus from his cramped student bedsit in Edinburgh. His debut, Knots and Crosses, was turned down by five publishers before landing a book deal. “It was last-chance saloon,” he recalls.

“We are going to name and shame them,” adds Rankin, a twinkle in his eye. “There is a wee Rebus exhibition on at the Writers’ Museum and I’ve got the letter from my agent saying: ‘Look, these five have turned it down, but I have sent it to Bodley Head and they have picked it up …’

“It was an inauspicious beginning. The first book wasn’t reviewed very widely, didn’t win any prizes and sold very few copies.”

Rankin went on to publish seven more books before Black and Blue, which drew on the notorious Bible John murders in Glasgow, proved his big breakthrough, winning the Crime Writers’ Association Gold Dagger for Fiction in 1997.

“That was the first proper inkling I got that I knew what I was doing,” he says. “It was the book that convinced me not to give up.”

As we sit in the beer garden of a pub in the shadow of Arthur’s Seat, Rankin is on good form. He is newly returned from a book tour of Australia and New Zealand, cheerfully admitting to mainlining caffeinated fizzy drinks in a bid to stave off the worst of the jetlag.

Later we take a walk, sauntering through the narrow cobbled lanes of Duddingston to see a tapestry exhibition which includes a couple of pieces by his wife Miranda. Despite his travel-induced fatigue, Rankin has the keen eye of a hawk, taking in every detail and filing it away for future use.

The writer remains hugely fond of Rebus as a protagonist. “He is a great character and a useful way of looking at the world,” he says. “People often ask: ‘How do you keep a series fresh when you’ve been writing about somebody for 30 years?’ But each book feels very different from the one before.

“Rebus has got older and he now has illnesses to deal with. He’s not the guy he was in the early books. He can’t use his physical presence to intimidate people the way he used to. I quite like that he is physically and mentally changing.”

Rankin is sanguine, however, when asked if he can see an end point for Rebus. “He is 70. The first book was 30 years ago and he was 40 then,” he says. “The five years after Exit Music [in 2007] that I didn’t write about him I’ve knocked those years off the slate so in my mind he is 65.

“There is only so much I can do with him. Taking him forward in more or less real time, I can’t imagine Rebus in his eighties solving crimes. I can’t imagine me in my seventies writing them. I take it one book at a time and I always have done. There has never been a plan.”

Would Rankin ever kill Rebus off? “I don’t know – maybe,” he says, smiling at my sharp intake of breath. “Why not? When I’m halfway through writing a book that’s when I start to see the ending. I could start a book and by the end think: ‘Oh, he’s not there any more …’”

The author has described Rebus as being Mr Hyde to his own Dr Jekyll. “He is a maverick and I have never been a maverick,” says Rankin. “He is up for a fight and I’ve never been up for a fight. He smokes and I’ve never smoked. He is a loner and I don’t think I have ever been much of a loner.

“He has a way of looking at the world and is a very different character from me. I get to hang out with him and have adventures whereas in real life I don’t have that many adventures, I just sit in my room making stuff up in my head.”

Edinburgh is more than simply a backdrop. The city has gifted a wealth of hidden stories that have inspired Rankin’s work. Here he shares some of the classics.

KNOTS AND CROSSES (1987)

“This idea came when I was doing a PhD on Dame Muriel Spark at Edinburgh University. Her character Miss Jean Brodie is descended from Deacon William Brodie, who was a criminal in 18th-century Edinburgh: a gentleman by day and a burglar by night.

“Brodie was a carpenter and member of the establishment, but had a gang of thieves who would break into houses. In Robert Louis Stevenson’s childhood bedroom there was a wardrobe made by Brodie. His nursemaid would tell him the story of this guy who was good and evil.

“When Stevenson grew up he wrote The Strange Case of Dr Jekyll and Mr Hyde. So, Miss Jean Brodie took me to William Brodie which, in turn, took me to Jekyll and Hyde.

“I was obsessed with it because in the mid-1980s, when I was writing the book, Edinburgh was a real Jekyll and Hyde city. On the surface it was all niceness and light with bagpipes, the castle and tourism, but underneath there was social, drug and prostitution problems that weren’t being addressed.

“The reader is supposed to think Rebus could be the killer because he is having blackouts and has a locked room in his flat that he never talks about. I was putting in all these clues, although nobody ever thought he was the bloody killer.

“I wrote a second Rebus novel called Hide and Seek (1991) in which there is a club called Hyde’s where prominent businessmen go to get their jollies of an evening. It wasn’t about an individual as such, but rather society as this Jekyll and Hyde character. But still nobody got it.

“There has been a lot of gentrification in Edinburgh and many of the places I used in the books are now unrecognisable. The tenements have been knocked down and social housing is better quality but then there are parts that haven’t changed in 200 years.

"Stevenson could come back and think: ‘This hasn’t changed all that much.’ Possibly even Deacon Brodie could come back and say that.

“It is still a city that has huge gaps between the rich and the poor. The metaphor is actually there with the New Town and the Old Town. The New Town is rational and planned, while the Old Town still feels quite chaotic.

“You have the Jekyll and Hyde in the street plan in front of you. I like that.”

MORTAL CAUSES (1994)

“This was written before Mary King’s Close opened as a tourist attraction and it wasn’t commonly known there was a hidden street beneath the City Chambers on the Royal Mile.

“The only way you could get access was to go into the City Chambers and ask. They ran a wee tour organised by someone who worked there and when he got enough folk he would take you round.

“One evening about eight of us trooped down with this guide who just had a torch. It was like a maze of rooms and passageways going off into the distance.

“I like the story – although it is half fictional – that the reason the close still exists is because people moved out due to the plague [in 1645]. When they moved back afterwards they felt it was haunted and refused to live there so it was paved over and the City Chambers built on top. Apparently that is only half true, and there were people living there until the 19th century.

“There was one room where it was said that a child had got stuck up a chimney and died. It was reputed to be haunted and people who went down would leave toys and sweets. It was the freakiest thing, just one wee room with a fireplace and a few little dolls left around.

“Another room had hooks hanging from the ceiling. I immediately saw a crime scene and a body hanging from them. I heard – or I misheard – our guide say that it was a butcher’s shop.

“Someone later told me it was never a butcher’s shop; it was an ironmongers and they would have pots and pans hanging from the hooks. But in my book I made it a butcher’s shop and the line was there was meat still hanging from one of them …”

BLACK AND BLUE (1997)

“I had been reading American crime writer James Ellroy and realised that some of his subject matter was based on real gangsters and murders in Los Angeles during the 1940s and 50s. I thought: ‘Wait, you can do that in fiction?’

“I started to think about what the biggest unsolved crime in Scotland is and Bible John* jumped into my head. I don’t often get these high-concept ideas but I thought: ‘What if someone was copying Bible John and he has to come back to find them before the police?’

“What mattered to me wasn’t Bible John per se, but what it became: this mythology where people turn characters into folk tale monsters. When I was a wee kid my mum and dad would say: ‘Make sure you are home before dark or Bible John will get you.’ He became a bogeyman.

“There are loads of theories. One is that Bible John may have got done for something else, put in jail and then died. Another is that he might have emigrated.

“My idea was that because the third victim’s sister got a good look at him, Bible John had buggered off and was living abroad until a copycat killer seemed to be taking away his glory. He comes back to Scotland to stop the copycat.

“After the book was published I was pretty nervous for a couple of years. Whenever I was doing a reading or talk in a bookshop in Scotland I would always be looking around for a guy of a certain age with a wee gap between his teeth just in case it was him.”

* Bible John is the nickname of a serial killer believed to have murdered three women after meeting them at the Barrowland ballroom in Glasgow between 1968 and 1969.

SET IN DARKNESS (2000)

“I was reading an in-flight magazine during a book tour of America and it featured a walking tour of Edinburgh. I thought: ‘This won’t tell me anything I don’t know …’ but it mentioned Queensberry House and that an act of cannibalism took place there.

“I went to Queensberry House when they were doing an archaeological survey prior to the rebuilding work for the Scottish Parliament. We were in the bowels of the place which had been the kitchens when it was a hospital. They were excavating the fireplace where the act of cannibalism happened.

“The Duke of Queensberry was out celebrating the 1707 Act of Union between Scotland and England. His son, left behind at Queensberry House, is said to have killed a servant and roasted him alive in the fireplace.

“I was there as they prised away a wall to reveal that very fireplace. Of course, I said: ‘Could you just shine a torch in there?’ but there was nothing inside.

“In my imagination, though, I pictured Rebus being there as the wall was removed to reveal a recent body. I walked out thinking: ‘I’ve got the opening scene of my next book.’”

THE FALLS (2001)

“In 1836, 17 miniature coffins were discovered by children playing on Arthur’s Seat and some of them are displayed at the National Museum of Scotland in Edinburgh.

“I first heard about the coffins when I was being interviewed at the museum by a Japanese TV crew. A curator came up to me and said: ‘Mr Rankin, you should go and look at the wee coffins on the fourth floor.’ I had been to the museum many times with my kids but never to the fourth floor.

“If you go to the lifts, there is only floors one, three and five. Floor four you have to access from a different lift at the back of the main floor. It has a section to do with superstitions and death which includes these coffins, eight from the 17 originally found.

“They are only a few inches in size, intricately designed and made of light wood – I got to hold one once. Inside each of them is a tiny carved wooden figure that was clothed.

“I don’t think anyone knows exactly where they were found. It wasn’t a cave as such, more a cleft in the rock on the side of Arthur’s Seat. The children saw them lying on makeshift shelves.

“The display case panel says: ‘We don’t know why these coffins were there …’ and I thought: ‘Ah, a real-life mystery …’ Sometimes that is all it takes to get the juices flowing.

“There are various theories. The most compelling is they were made by a shoemaker who was a friend of [the 19th-century serial killers] Burke and Hare. There is metalwork on the coffins near identical to metalwork you would have found on shoes at the time.

“The shoemaker could have been leaving the coffins as a memorial: 17 victims and 17 coffins.”

RebusFest takes place across Edinburgh from June 30 until July 2. Visit ianrankin.net