Installing GHCi requires to change my path to use in terminal - haskell

[![I'm trying to write Haskell code in a text editor then run it with GHCi in my terminal. I successfully installed GHCi (I think), and am trying to run a command to run some code I wrote, but I there is no command found for ghci or ghc. Do I need to change my terminal path to where I downloaded/installed GHCI? Also if I change the path will it permanently change my starting path in terminal? Here's the last thing my terminal says. I've also tried stack ghci.
EDIT
My error is that the commands are not found when I run them in terminal.
I installed everything by running this command in my terminal and continuing to type YES when prompted.
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
The contents of /Users/Jack/.ghcup/env is
export PATH="$HOME/.cabal/bin:/Users/Jack/.ghcup/bin:$PATH"

Note to others reading this: I recommended ~/.profile instead of ~/.bashrc because I know from the original question (before it was revised) that the OP is using a Mac (more info on bash on Macs).
Try running these three commands in order in your terminal:
echo 'export PATH="$HOME/.cabal/bin:/Users/Jack/.ghcup/bin:$PATH"' >> ~/.profile
. ~/.profile
ghci
What this will do is modify your PATH environment variable as necessary so that your shell can find the ghci program. It will also store this modification in your ~/.profile so your PATH will have the correct value next time you log in.
Also if I change the path will it permanently change my starting path in terminal?
The PATH environment variable is not related to the initial working directory of your terminal. So no, your terminal's "starting path" will not be changed.

Just write . ~/.ghcup/env in the ~/.zshrc file. Another thing is restarting the terminal.

Related

Can't run ghci in Terminal

every time I type ghci into the terminal or a command I would execute through ghci it tells me zsh: command not found: ghci.
I'm super new to this and don't really know what to do?
Commands like cd and so on that are for the items on my Mac work just fine.
It sounds like bash was your shell when you installed GHC, but Apple later switched you to zsh. The problem is that it was only added to your path for bash. Look for a line in ~./bashrc or ~/.bash_profile that looks something like this:
[ -f "${GHCUP_INSTALL_BASE_PREFIX:=$HOME}/.ghcup/env" ] && source "${GHCUP_INSTALL_BASE_PREFIX:=$HOME}/.ghcup/env"
It might not look quite like that, but the important part is the reference to .ghcup/env. Once you find that line, copy it and add it to the end of ~/.zshrc. Then restart your shell and try again.
Here's the GUI version of it.
Open Ghcup GUI with the command
ghcup tui
You would notice something like this
GCHUP GUI:
For me when the ghc or ghci command was not working, there was a single tick beside GHC option.
Go to that option and press s to set. It worked for me.
You could try wirte . ~/.ghcup/env in the ~/.zshrc file. Another thing is restarting the terminal.

Automate a bash script

Im trying to install Anaconda on newly created EC2 instance using a bash script. While installation, it first asks to press enter then read through agreement(which I can skip by pressing q), then type yes to accept it. Once it's done, I have to type yes again to add PATH to .bashrc. I am trying to automate this but I'm not sure how it should be done. I tried to use Yes command, but it didn't work. I found out I can use expect command but for this I have to install its package first and It also asks to press some key(which I cannot automate) so I have to find some other way. It would be great if someone can provide some solution.
As #Dusan Bajic suggested, I installed Anaconda silently, which doesn't ask for any user input. I simply executed the following commands:
wget https://repo.anaconda.com/archive/Anaconda2-5.1.0-Linux-x86_64.sh -O anaconda.sh
bash anaconda.sh -b
where b is: Batch mode with no PATH modifications to ~/.bashrc. Assumes that you agree to the license agreement. Does not edit the .bashrc or .bash_profile files.
And then I added the PATH manually to .bashrc.
echo 'export PATH=/home/ec2-user/anaconda2/bin:$PATH' >> ~/.bashrc

Default bash environment changed. How do I revert it to default?

I am using AWS EC2 along with the CodeStar services.
I wanted to add the path to maven's binary to the PATH environment variable.
So I wrote it to the /etc/environment file and executed the command:
source /etc/environment
But it has now changed the default environment of the bash shell and now I am not able to execute any command. Even for a command like ls it gives output -bash: command not found
How do I revert back to the default settings. I tried whatever my brain could think of. But nothing helped. Would be glad to hear from the community.
In order to revert back to the default settings:
As #Cyrus wrote you should update the PATH variable
In the bash shell run the following command:
PATH="/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin"
Undo the changes to the /etc/environment
edit the /etc/environment using the same method you used before, and remove the PATH line you added to the file
You can use sudo vi /etc/environment or any other editor you prefer
Note: In my AWS machine, the /etc/environment file is empty.

Setting path variables and running Ruby script

This is my first time working with a Ruby script, and, in order to run this script, I have to first cd into the root of the project, which is /usr/local/bin/youtube-multiple-dl and then execute the script as bin/youtube-multiple-dl.
I tried setting the PATH variable
echo 'export PATH="$HOME/youtube-multiple-dl/bin:$PATH"' >> ~/.bash_profile
in hopes that I can run this from anywhere on the machine without having to cd to the project's root, however, no luck with that so far.
System: Ubuntu 15.04 server
Script Repo
My current way of executing the script is:
root#box15990:~# cd /usr/local/bin/youtube-multiple-dl
root#box15990:/usr/local/bin/youtube-multiple-dl# bin/youtube-multiple-dl
Desired way of executing script:
root#box15990:~# youtube-multiple-dl
How can I properly set the enviroment path for this script in order to run from anywhere?
echo 'export PATH="$HOME/youtube-multiple-dl/bin:$PATH"' >> ~/.bash_profile
isn't how we set a PATH entry.
The PATH is a list of directories to be searched, not a list of files.
Typically, the PATH should contain something like:
/usr/local/bin:/usr/bin
somewhere in it.
If it doesn't, then you want to modify it using a text editor, such as nano, pico or vim using one of these commands:
nano ~/.bash_profile
pico ~/.bash_profile
vim ~/.bash_profile
You probably want one of the first two over vim as vim, while being extremely powerful and one of the most-used editors in the world, is also not overly intuitive if you're not used to it. You can use man nano or man pico to learn about the other too.
Once your in your file editor, scroll to the bottom and remove the line you added. Then find the /usr/bin section in your PATH and add /usr/local/bin: before it. : is the delimiter between directories. That change will tell the shell to look in /usr/local/bin before /usr/bin, so that any things you added to the /usr/local/bin directory will be found before the system-installed code, which is in /usr/bin.
It's possible that there isn't a PATH statement in the file. If you don't see one, simply add:
export PATH=/usr/local/bin:$PATH
After modifying your ~/.bash_profile, save the file and exit the editor, and then restart your shell. You can do that by exiting and re-opening a terminal window, or by running:
exec $SHELL
at the command-line.
At that point, running:
echo $PATH
should reflect the change to your path.
To confirm that the change is in effect, you can run:
which youtube-multiple.dl
and you should get back:
/usr/local/bin/youtube-multiple.dl
At that point you should be able to run:
youtube-multiple.dl -h
and get back a response showing the built-in help. This is because the shell will search the path, starting with the first defined directory, and continue until it exhausts the list, and will execute the first file matching that name.
Because of the difficulties you're having, I'd strongly recommend reading some tutorials about managing a *nix system. It's not overly hard to learn the basics, and having an understanding of how the shell finds files and executes them is essential for anyone programming a scripting language like Ruby, Python, Perl, etc. We're using the OS constantly, installing files for system and user's use, and doing so correctly and safely is very important for the security and stability of the machine.

Can't install heroku toolbelt on Linux Mint Path invalid

Attemping
wget -qO- https://toolbelt.heroku.com/install.sh | sh
as instructed by this article yields this message.
Add the Heroku CLI to your PATH using: $ echo 'PATH="/usr/local/heroku/bin:$PATH"' >> ~/.profile
So I type
echo 'PATH="/usr/local/heroku/bin:$PATH"' >> ~/.profile
and I see that the string has been added to the .profile file, located at /home/myusername/
Then I run the command again
wget -qO- https://toolbelt.heroku.com/install.sh | sh
and I still get the same error.
I'm not sure if what current directory I'm running these commands from is important, but I've tried being in the default terminal directory, rather than my specific app, and still the same results.
I found out that the /usr/ directory is directly underneath the / directory, NOT my /home/myusername/ directory so I modified the path to go up two levels, first like so:
PATH="../../usr/local/heroku/bin:$PATH"
But even that didn't seem to work - I don't get the "heroku" command available.
You have to log into linux profile again to activate the ~/.profile script, thus adding the path. Either log out of the linux session, and then lack back in, or restart your computer.
You can also do source ~/.profile, but this will only enable heroku commands in the current terminal, and not work if you close it.

Resources