The story goes that one of the early electromechanical computers suffered a failure because an insect had crawled into the machine and been squashed between the moving parts of a relay switch, thereby jamming it. The incident was written up in the logbook and spread from there throughout the whole of the infant computer industry. However, although the account seems to be genuine, the word is older: the event was recorded as an amusement for posterity precisely because the term 'bug' was already in use.
The term in fact originates not with computer pioneers, but with engineers of a much earlier generation. The first example cited in the 20-volume historical Oxford English Dictionary is from the Pall Mall Gazette of 11 March 1889:
Mr. Edison, I was informed, had been up the two previous nights discovering 'a bug' in his phonograph - an expression for solving a difficulty, and implying that some imaginary insect has secreted itself inside and is causing all the trouble.
It seems clear from this that the original 'bug', though it was indeed an insect, was in fact imaginary.
Reference : Hi Five - Word Origins.http://oxforddictionaries.com/words/was-the-first-computer-bug-a-real-insect