How many public keys and private keys are needed for RSA? I am just learning about RSA encrytion and I am somewhat confused.
First two prime numbers $p$ and $q$ must be chosen and multiplied to get $n$. Then we compute Euler function $\varphi (n) = (p-1)(q-1)$.
The public key $e$ is generated by choosing a random number that fulfills the condition $gcd(e, \varphi(n)) = 1$. And the private key $d$ is then computed $d * e \:\: mod\:\varphi(n) = 1$.
So if Alice wants to send a message to Bob, a pair of public and private key is generated. But if Bob wants to send something back to Alice, must another pair of public and private key be generated?
If this is the case, does it mean that for RSA between $x$ parties, there must be in total $x(x-1)$ keys (public and private) generated?
So if Alice wants to send a message to Bob, a pair of public and private key is generated. But if Bob wants to send something back to Alice, must another pair of public and private key be generated?

Yes. Bob's public/private key pair, which protected the Alice-to-Bob transfer, is not usable to send data to Alice. However it's usable by anyone [assumed knowing Bob's public key $(n_b,e_b)$, trusting that to be matching Bob's private key $(n_b,d_b)$, and that Bob will not reveal that private key or use it unwisely] in order to send a confidential message to Bob.
Hence each user may need a single public/private key pair, yet the system allow anyone to send a confidential message to anyone.


If this is the case, does it mean that for RSA between $x$ parties, there must be in total $x(x-1)$ keys (public and private) generated?

No. As far as counting how many public/private key pairs there are, a good analogy is public phone number and private phone: we need as many phone numbers, and corresponding phones, as there are users.