Hopefully you have attended several operas and have an understanding about this artistic genre. You should go to the library and read some books about this genre as well as reading the scores to several. There are writing classes that can be found online as well as through universities that have a fine arts program.
First of all, you have to have some talent in music, then you should go to the conservatory of music or to the music faculty at the university, then listen some operas before doing anything else.
In order to write an opera for people to fully enjoy you must prepare yourself by researching your style of charictors. The charictors should be individuals that can be related to so that your audience feels the aura of the opera.