This course has been updated! We now recommend you take the Full Stack for Front-End Engineers, v2 course.
Transcript from the "Installing Gulp" Lesson
>> Jem: So next we need to install Gulp. So we wanna install Gulp globally, so when we run it, we run it from the command line. Otherwise we have to do /nodeModules/Gulp/ something, and that's messy, so we install things globally. So, everybody do npm install -g Gulp. This one, it doesn't matter where you install it from.
[00:00:21] Doesn't have to be var, because we're installing it globally.
>> Jem: And I'm gonna go ahead and run that as well. So mpm i -g gulp
>> Jem: Permission error. All that work for nothing. Yes because we're golf and solitude/usr/local/lib. It's not owned by a user, it's owned by root.
[00:01:02] So, the naive approach is let's just change ownership of local lib to the current owner. Don't do that, it'll break everything. So, what we have to do in this case is we're going to follow MPMs steps. I didn't even make slides for it because their steps are so much better than ours.
[00:01:18] But what we're essentially gonna do is we're gonna point our npm repo into a different repo that we own, okay? So everybody that jumped ahead and tried to global install, you probably ran into this error, and you're like, what did I do wrong? Nothing, that was deliberate. So,
>> Jem: First we need to make this directory, because it doesn't exist. This is I've run through all these slides before. Yeah, thanks. I've read through all these slides before, and their instructions will tell you to make something that will throw an error. So first, make this directory. sudo mkdir -p /usr/local/lib/node_modules.
[00:02:00] Because that currently doesn't exist, so when we run the NPM steps, it will break. So, I'm going to do that as well. So, sudo mkdir dash p
>> Speaker 2: mkdir is spelled wrong.
>> Jem: Thank you
>> Jem: Local/lib. I think that's what it was. Node_modules. Okay. Everybody with me so far?
[00:02:51] Excellent. So we're just gonna use the npm docs for this particular incidents because well, they're pretty solid. And honestly, this is how I get stuffed on as well. I look stuff up and I do it. So, just a common problem, enough that they have documentation. So first, let's run this command.
[00:03:07] Let me make this bigger. Let's run this command in our server and see what comes up. So, MPM. Config. Get prefix. And this is just gonna tell, it's just gonna tell us where MPMs actually looking for the global installs. Let me clear this out. Config. Flushes your local perfect so that's that's exactly what it should be.
[00:03:41] If it's not, well it is because we're all the same box again this is the importance of using the same distribution. I've run into the thing where if you use something slightly different at this point if you're running npm config get prefix it could be /usr instead of /usr/local.
[00:03:55] If it's /usr you have to go through all these steps. This is why we all are on the same distribution, lessons learned. So, what we're gonna do is we're gonna chown, we're gonna change ownership of that directory along with the rest of these directories to our current user.
[00:04:13] So, that way we don't have to suedo install everything. You should never, ever suedo MPM install anything because when you install it you're installing as the root user, not your current user. So in this case, I'm going to copy paste because I'm lazy and it's 3:00. But feel free to type out if you want to be a better than me.
[00:04:37] And I'm just going to show this. Cool. So now, -g gulp, hopefully this works, fingers crossed. And it installed correctly, so everything ran, probably cuz I copy pasted it, didn't trust my own typing.
>> Jem: This who am I command just the case, it tells you what user you are, so if you run that as a dollar sign who am I?
[00:05:11] It's gonna try to execute this as an actual command, which jem is not a package. So.
>> Speaker 2: You could have also used $USER at that point.
>> Jem: Absolutely, I should have just used that, but I was copy and pasting.
>> Jem: So, is everybody with me so far?
>> Jem: We copied this from the npm docs.
[00:05:37] And we're just changing ownership of the npm directory to our current users so that we don't have to pseudo-install global modules.
>> Jem: Thank, Mark, for pasting that in.
>> Jem: Yes, there we are, slide 124. We have about 11 more to go. So, almost there.
>> Jem: Okay so now gulp Let's go ahead and make sure gulp is up and running.
[00:06:15] Now make sure I'm in my working directory. Clear. So, I should be able to run gulp build and all the tasks complete successfully. If you have a syntax error, you're about to discover that you have a syntax error at this point. The Gulp task will not complete.
>> Jem: If we ls our dist file, we see that we have only two files that we're gonna serve out for our web page main.min.css and main.min.js file
>> Jem: Okay so, here's our Gulp locally, globally, we have the ability now to install npm modules globally without having a pseudo command, which is very useful. I have done the pseudo install, and it's a nasty business that you just have to keep pseudoing every single time. And it's just unpleasant.
[00:07:26] So, it's a little bit extra work to do it right the first time, but it's better in the long run.