Stellar first chapters are a bear to write. They are also essential if you want to sell your book to a publisher. Most "samples" of manuscripts include the first chapter.
Equally important are ending chapters. But for a different reason: your reader. If a reader is swept away by the last pages, they are more likely to (1) read the book again and (2) recommend it to a friend. Both huge compliments and great ways to get your book read by a lot of people.
Best way to learn how to write these two most-difficult parts of a book? For me, it's by reading and studying other writers. And by allowing the beginning and ending of your own book to evolve slowly--possibly out of step with the rest of the manuscript.
I also learned via two other methods.