The G-major chord has the notes G B and D.
Now, the difference between the two chord shapes you posted, is that in the first you play a D on the B-string (3rd fret, fifth string) and in the second example, the open B is played (open fifth string).
Essentially it is the same chord, because both the D and the B are part of the overall G-major chord shape. Which one to use will depend on the song you're playing, but harmonically it should not matter that much.
There are many more chord shapes for the G-major:
24 G-major shapes
As long as you're playing a G, B and D, it will be a G-major.
See all possible positions of G, B and D on the guitar neck, to come up with your own chord shape:
All G-major notes on guitar