There are a few things to unpack here.
First, regardless of the AES mode being used (GCM, CBC, ECB, CTR, etc), if you are using AES-256, then the key must be 256 bits in length. To generate a random 256-bit key, encoded in hexadecimal format, you can use the following command:
head /dev/urandom | sha256sum
This produces a random 256-bit key, such as:
3fd00454580de44ea216d8b7b234267a2a6a6aec7e56d2b38e641a45597af0f2
Now, you can use this key with an iv with openssl to encrypt some plain text using aes-256-cbc, like so:
echo -n 'hello world' | openssl aes-256-cbc -e -K 3fd00454580de44ea216d8b7b234267a2a6a6aec7e56d2b38e641a45597af0f2 -iv 302775dfc35a35c8081bbc6fdeacbd86 | xxd -p
This produces the cyphertext:
7d5b44298bf959af149a0086d79334e6
Now, you can decrypt the ciphertext using the same key and iv, to produce the original plainext, like so:
echo -n '7d5b44298bf959af149a0086d79334e6' | xxd -p -r | openssl aes-256-cbc -d -K 3fd00454580de44ea216d8b7b234267a2a6a6aec7e56d2b38e641a45597af0f2 -iv 302775dfc35a35c8081bbc6fdeacbd86
This produces:
hello world
However, you asked about using openssl to do AES encryption using GCM mode, not CBC mode. Unfortunately, this is not possible with the command line interface for openssl, because AES-GCM is not supported. For more info on this, see https://www.openssl.org/docs/man1.1.1/man1/enc.html, and scroll down to the section 'supported ciphers, and note where it reads:
The enc program does not support authenticated encryption modes like
CCM and GCM, and will not support such modes in the future. The enc
interface by necessity must begin streaming output (e.g., to standard
output when -out is not used) before the authentication tag could be
validated, leading to the usage of enc in pipelines that begin
processing untrusted data and are not capable of rolling back upon
authentication failure.