As the others have already stated: Yes, it is possible, but ...
However, I feel that the really important message has not been transported yet: Building a wheel is not easy for the uninitiated.Yes, it can be done. Yes, you will likely get something that looks like a true wheel. But you may easily end up with many broken spokes the weeks after.
The critical part about building a wheel is, that you need to apply even tension to the spokes. Fail to do so, and they may break very quickly. And with even tension, I really mean very even. It won't suffice that they feel evenly tensioned to the touch, the tolerances are surprisingly small. If you have a musical ear, that helps a lot, as you can just tune your spokes (that's what I do, at least). However, doing so takes time. Time that may be better spent on other pursuits. After all, when you adjust the tension of one spoke, 35 other spokes have their tensions changed slightly as well...
That said, building a rear-wheel with a cassette is an additional challenge, as you need to build it asymmetrically. Consequently, the spokes on one side need a much higher tension than on the other side. With the tuning approach, that's two different tones, the exact pitch of which depends on the geometry that you aim for.
So, if your goal is to get to know how your bike is built, go for it. You can learn it. But expect to pay for these skills with a significant amount of time, and likely broken spokes. If your goal is just to save a penny, think twice: buying a new wheel may save more in terms of time than you can save in money by building yourself, and the bought wheel has less risk of failing quickly.
Of course, this economic consideration heavily depends on the price tags of the parts that you are trying to save. If your rim costs 500$, you better keep it, no matter how much time you need to invest into building the wheel. However, for a standard, off-the-shelf 20$ rim, buying a whole wheel is very likely the more economic option.