Ian McKellen was the first actor to play Gandalf in a live-action film adaptation of Tolkien’s works.
McKellen portrayed Gandalf in Peter Jackson’s The Lord of the Rings film trilogy, beginning with The Fellowship of the Ring in 2001. He returned as the wizard in The Two Towers and The Return of the King, and later appeared in The Hobbit trilogy, whose story takes place earlier in the chronology.
His performance distinguished Gandalf the Grey from Gandalf the White through changes in costume, movement, and authority. McKellen received an Academy Award nomination for Best Supporting Actor for The Fellowship of the Ring.
Christopher Lee played Saruman in the same trilogy, while Ian Holm played Bilbo Baggins. The animated 1978 film The Lord of the Rings included Gandalf as a character, but it was not a live-action production, so it does not change the answer to this question.