How do you create a new gameobject froms code?

I tried

GameObject.CreatePrimitive(PrimitiveType.Cube);

But nothing happens.

That just returns a gameobject, you then need to Instantiate it.

Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cube));

Create primitive will create an in scene object. No need to Instantiate.

You can also simply call new GameObject, which is often more relevant then creating a cube.